@lifeready/core 0.6.0-beta.1

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 (225) hide show
  1. package/README.md +62 -0
  2. package/bundles/lifeready-core.umd.js +15939 -0
  3. package/bundles/lifeready-core.umd.js.map +1 -0
  4. package/bundles/lifeready-core.umd.min.js +2 -0
  5. package/bundles/lifeready-core.umd.min.js.map +1 -0
  6. package/esm2015/lib/_common/ast.js +40 -0
  7. package/esm2015/lib/_common/deferred-promise.js +24 -0
  8. package/esm2015/lib/_common/exceptions.js +157 -0
  9. package/esm2015/lib/_common/queries.gql.js +190 -0
  10. package/esm2015/lib/_common/run-outside-angular.js +79 -0
  11. package/esm2015/lib/_common/types.js +1 -0
  12. package/esm2015/lib/_common/utils.js +44 -0
  13. package/esm2015/lib/api/contact-card.gql.js +79 -0
  14. package/esm2015/lib/api/contact-card.service.js +154 -0
  15. package/esm2015/lib/api/contact-card2.gql.js +60 -0
  16. package/esm2015/lib/api/contact-card2.service.js +103 -0
  17. package/esm2015/lib/api/file.service.js +74 -0
  18. package/esm2015/lib/api/item2.gql.js +110 -0
  19. package/esm2015/lib/api/item2.service.js +311 -0
  20. package/esm2015/lib/api/key-exchange.gql.js +188 -0
  21. package/esm2015/lib/api/key-exchange.service.js +442 -0
  22. package/esm2015/lib/api/key-exchange.types.js +18 -0
  23. package/esm2015/lib/api/key-exchange2.gql.js +171 -0
  24. package/esm2015/lib/api/key-exchange2.service.js +479 -0
  25. package/esm2015/lib/api/lock.gql.js +40 -0
  26. package/esm2015/lib/api/lock.service.js +64 -0
  27. package/esm2015/lib/api/lr-apollo.service.js +46 -0
  28. package/esm2015/lib/api/lr-graphql/index.js +6 -0
  29. package/esm2015/lib/api/lr-graphql/lr-graphql.service.js +155 -0
  30. package/esm2015/lib/api/lr-graphql/lr-merged-mutation.js +213 -0
  31. package/esm2015/lib/api/lr-graphql/lr-mutation-base.js +51 -0
  32. package/esm2015/lib/api/lr-graphql/lr-mutation.js +48 -0
  33. package/esm2015/lib/api/lr-graphql/lr.service.js +18 -0
  34. package/esm2015/lib/api/message.service.js +138 -0
  35. package/esm2015/lib/api/persist.service.js +181 -0
  36. package/esm2015/lib/api/query-processor/common-processors.service.js +93 -0
  37. package/esm2015/lib/api/query-processor/index.js +3 -0
  38. package/esm2015/lib/api/query-processor/query-processor.service.js +192 -0
  39. package/esm2015/lib/api/query-processor/tp-password-reset-processor.service.js +109 -0
  40. package/esm2015/lib/api/shared-contact-card.service.js +119 -0
  41. package/esm2015/lib/api/shared-contact-card2.gql.js +41 -0
  42. package/esm2015/lib/api/shared-contact-card2.service.js +117 -0
  43. package/esm2015/lib/api/time.service.js +146 -0
  44. package/esm2015/lib/api/types/graphql.types.js +7 -0
  45. package/esm2015/lib/api/types/index.js +3 -0
  46. package/esm2015/lib/api/types/lr-graphql.types.js +71 -0
  47. package/esm2015/lib/auth/auth.config.js +57 -0
  48. package/esm2015/lib/auth/auth.gql.js +48 -0
  49. package/esm2015/lib/auth/auth.types.js +27 -0
  50. package/esm2015/lib/auth/idle.service.js +168 -0
  51. package/esm2015/lib/auth/idle.types.js +7 -0
  52. package/esm2015/lib/auth/lbop.service.js +355 -0
  53. package/esm2015/lib/auth/life-ready-auth.service.js +333 -0
  54. package/esm2015/lib/auth/password.service.js +320 -0
  55. package/esm2015/lib/auth/register.service.js +172 -0
  56. package/esm2015/lib/auth/two-factor.service.js +74 -0
  57. package/esm2015/lib/category/category-meta.service.js +99 -0
  58. package/esm2015/lib/category/category.gql.js +406 -0
  59. package/esm2015/lib/category/category.service.js +390 -0
  60. package/esm2015/lib/category/category.types.js +29 -0
  61. package/esm2015/lib/cryptography/cryptography.types.js +11 -0
  62. package/esm2015/lib/cryptography/encryption.service.js +189 -0
  63. package/esm2015/lib/cryptography/key-factory.service.js +237 -0
  64. package/esm2015/lib/cryptography/key-graph.service.js +280 -0
  65. package/esm2015/lib/cryptography/key-meta.service.js +200 -0
  66. package/esm2015/lib/cryptography/key.service.js +124 -0
  67. package/esm2015/lib/cryptography/slip39.service.js +169 -0
  68. package/esm2015/lib/cryptography/web-crypto.service.js +29 -0
  69. package/esm2015/lib/life-ready.config.js +84 -0
  70. package/esm2015/lib/life-ready.module.js +74 -0
  71. package/esm2015/lib/plan/plan.gql.js +123 -0
  72. package/esm2015/lib/plan/plan.service.js +149 -0
  73. package/esm2015/lib/plan/plan.types.js +11 -0
  74. package/esm2015/lib/record/record-attachment.service.js +101 -0
  75. package/esm2015/lib/record/record.gql.js +179 -0
  76. package/esm2015/lib/record/record.service.js +206 -0
  77. package/esm2015/lib/record/record.types.js +15 -0
  78. package/esm2015/lib/record-type/record-type.service.js +75 -0
  79. package/esm2015/lib/record-type/record-type.types.js +28 -0
  80. package/esm2015/lib/scenario/approvals/scenario-approval.gql.js +105 -0
  81. package/esm2015/lib/scenario/approvals/scenario-approval.types.js +1 -0
  82. package/esm2015/lib/scenario/approvals/scenario-approver.service.js +300 -0
  83. package/esm2015/lib/scenario/claimants/scenario-claimant.gql.js +52 -0
  84. package/esm2015/lib/scenario/claimants/scenario-claimant.service.js +97 -0
  85. package/esm2015/lib/scenario/claimants/scenario-claimant.types.js +1 -0
  86. package/esm2015/lib/scenario/receivers/scenario-receiver.gql.js +150 -0
  87. package/esm2015/lib/scenario/receivers/scenario-receiver.service.js +229 -0
  88. package/esm2015/lib/scenario/receivers/scenario-receiver.types.js +1 -0
  89. package/esm2015/lib/scenario/scenario-setup.service.js +269 -0
  90. package/esm2015/lib/scenario/scenario.gql.js +368 -0
  91. package/esm2015/lib/scenario/scenario.service.js +611 -0
  92. package/esm2015/lib/scenario/scenario.types.js +64 -0
  93. package/esm2015/lib/search/search.gql.js +62 -0
  94. package/esm2015/lib/search/search.service.js +156 -0
  95. package/esm2015/lib/search/search.types.js +6 -0
  96. package/esm2015/lib/trusted-parties/tp-password-reset-request.service.js +112 -0
  97. package/esm2015/lib/trusted-parties/tp-password-reset-user.service.js +266 -0
  98. package/esm2015/lib/trusted-parties/tp-password-reset.gql.js +232 -0
  99. package/esm2015/lib/trusted-parties/tp-password-reset.service.js +300 -0
  100. package/esm2015/lib/trusted-parties/trusted-party.gql.js +148 -0
  101. package/esm2015/lib/trusted-parties/trusted-party.service.js +326 -0
  102. package/esm2015/lib/trusted-parties/trusted-party.types.js +41 -0
  103. package/esm2015/lib/trusted-parties/trusted-party2.gql.js +87 -0
  104. package/esm2015/lib/trusted-parties/trusted-party2.service.js +215 -0
  105. package/esm2015/lib/users/profile-details.service.js +214 -0
  106. package/esm2015/lib/users/profile.gql.js +97 -0
  107. package/esm2015/lib/users/profile.service.js +169 -0
  108. package/esm2015/lib/users/profile.types.js +34 -0
  109. package/esm2015/lib/users/user.gql.js +60 -0
  110. package/esm2015/lib/users/user.service.js +79 -0
  111. package/esm2015/lib/users/user.types.js +5 -0
  112. package/esm2015/lifeready-core.js +10 -0
  113. package/esm2015/public-api.js +81 -0
  114. package/fesm2015/lifeready-core.js +13290 -0
  115. package/fesm2015/lifeready-core.js.map +1 -0
  116. package/lib/_common/ast.d.ts +11 -0
  117. package/lib/_common/deferred-promise.d.ts +12 -0
  118. package/lib/_common/exceptions.d.ts +109 -0
  119. package/lib/_common/queries.gql.d.ts +10 -0
  120. package/lib/_common/run-outside-angular.d.ts +14 -0
  121. package/lib/_common/types.d.ts +10 -0
  122. package/lib/_common/utils.d.ts +3 -0
  123. package/lib/api/contact-card.gql.d.ts +7 -0
  124. package/lib/api/contact-card.service.d.ts +52 -0
  125. package/lib/api/contact-card2.gql.d.ts +34 -0
  126. package/lib/api/contact-card2.service.d.ts +49 -0
  127. package/lib/api/file.service.d.ts +18 -0
  128. package/lib/api/item2.gql.d.ts +96 -0
  129. package/lib/api/item2.service.d.ts +177 -0
  130. package/lib/api/key-exchange.gql.d.ts +9 -0
  131. package/lib/api/key-exchange.service.d.ts +39 -0
  132. package/lib/api/key-exchange.types.d.ts +196 -0
  133. package/lib/api/key-exchange2.gql.d.ts +125 -0
  134. package/lib/api/key-exchange2.service.d.ts +187 -0
  135. package/lib/api/lock.gql.d.ts +27 -0
  136. package/lib/api/lock.service.d.ts +25 -0
  137. package/lib/api/lr-apollo.service.d.ts +15 -0
  138. package/lib/api/lr-graphql/index.d.ts +5 -0
  139. package/lib/api/lr-graphql/lr-graphql.service.d.ts +60 -0
  140. package/lib/api/lr-graphql/lr-merged-mutation.d.ts +27 -0
  141. package/lib/api/lr-graphql/lr-mutation-base.d.ts +28 -0
  142. package/lib/api/lr-graphql/lr-mutation.d.ts +8 -0
  143. package/lib/api/lr-graphql/lr.service.d.ts +9 -0
  144. package/lib/api/message.service.d.ts +58 -0
  145. package/lib/api/persist.service.d.ts +31 -0
  146. package/lib/api/query-processor/common-processors.service.d.ts +36 -0
  147. package/lib/api/query-processor/index.d.ts +2 -0
  148. package/lib/api/query-processor/query-processor.service.d.ts +18 -0
  149. package/lib/api/query-processor/tp-password-reset-processor.service.d.ts +15 -0
  150. package/lib/api/shared-contact-card.service.d.ts +33 -0
  151. package/lib/api/shared-contact-card2.gql.d.ts +36 -0
  152. package/lib/api/shared-contact-card2.service.d.ts +45 -0
  153. package/lib/api/time.service.d.ts +16 -0
  154. package/lib/api/types/graphql.types.d.ts +29 -0
  155. package/lib/api/types/index.d.ts +2 -0
  156. package/lib/api/types/lr-graphql.types.d.ts +385 -0
  157. package/lib/auth/auth.config.d.ts +5 -0
  158. package/lib/auth/auth.gql.d.ts +15 -0
  159. package/lib/auth/auth.types.d.ts +66 -0
  160. package/lib/auth/idle.service.d.ts +40 -0
  161. package/lib/auth/idle.types.d.ts +10 -0
  162. package/lib/auth/lbop.service.d.ts +91 -0
  163. package/lib/auth/life-ready-auth.service.d.ts +46 -0
  164. package/lib/auth/password.service.d.ts +78 -0
  165. package/lib/auth/register.service.d.ts +25 -0
  166. package/lib/auth/two-factor.service.d.ts +15 -0
  167. package/lib/category/category-meta.service.d.ts +23 -0
  168. package/lib/category/category.gql.d.ts +45 -0
  169. package/lib/category/category.service.d.ts +67 -0
  170. package/lib/category/category.types.d.ts +79 -0
  171. package/lib/cryptography/cryptography.types.d.ts +83 -0
  172. package/lib/cryptography/encryption.service.d.ts +41 -0
  173. package/lib/cryptography/key-factory.service.d.ts +38 -0
  174. package/lib/cryptography/key-graph.service.d.ts +33 -0
  175. package/lib/cryptography/key-meta.service.d.ts +44 -0
  176. package/lib/cryptography/key.service.d.ts +36 -0
  177. package/lib/cryptography/slip39.service.d.ts +43 -0
  178. package/lib/cryptography/web-crypto.service.d.ts +5 -0
  179. package/lib/life-ready.config.d.ts +14 -0
  180. package/lib/life-ready.module.d.ts +5 -0
  181. package/lib/plan/plan.gql.d.ts +11 -0
  182. package/lib/plan/plan.service.d.ts +33 -0
  183. package/lib/plan/plan.types.d.ts +31 -0
  184. package/lib/record/record-attachment.service.d.ts +16 -0
  185. package/lib/record/record.gql.d.ts +14 -0
  186. package/lib/record/record.service.d.ts +25 -0
  187. package/lib/record/record.types.d.ts +57 -0
  188. package/lib/record-type/record-type.service.d.ts +11 -0
  189. package/lib/record-type/record-type.types.d.ts +50 -0
  190. package/lib/scenario/approvals/scenario-approval.gql.d.ts +7 -0
  191. package/lib/scenario/approvals/scenario-approval.types.d.ts +63 -0
  192. package/lib/scenario/approvals/scenario-approver.service.d.ts +32 -0
  193. package/lib/scenario/claimants/scenario-claimant.gql.d.ts +5 -0
  194. package/lib/scenario/claimants/scenario-claimant.service.d.ts +17 -0
  195. package/lib/scenario/claimants/scenario-claimant.types.d.ts +18 -0
  196. package/lib/scenario/receivers/scenario-receiver.gql.d.ts +8 -0
  197. package/lib/scenario/receivers/scenario-receiver.service.d.ts +30 -0
  198. package/lib/scenario/receivers/scenario-receiver.types.d.ts +54 -0
  199. package/lib/scenario/scenario-setup.service.d.ts +22 -0
  200. package/lib/scenario/scenario.gql.d.ts +34 -0
  201. package/lib/scenario/scenario.service.d.ts +58 -0
  202. package/lib/scenario/scenario.types.d.ts +217 -0
  203. package/lib/search/search.gql.d.ts +1 -0
  204. package/lib/search/search.service.d.ts +25 -0
  205. package/lib/search/search.types.d.ts +20 -0
  206. package/lib/trusted-parties/tp-password-reset-request.service.d.ts +20 -0
  207. package/lib/trusted-parties/tp-password-reset-user.service.d.ts +41 -0
  208. package/lib/trusted-parties/tp-password-reset.gql.d.ts +218 -0
  209. package/lib/trusted-parties/tp-password-reset.service.d.ts +131 -0
  210. package/lib/trusted-parties/trusted-party.gql.d.ts +9 -0
  211. package/lib/trusted-parties/trusted-party.service.d.ts +44 -0
  212. package/lib/trusted-parties/trusted-party.types.d.ts +102 -0
  213. package/lib/trusted-parties/trusted-party2.gql.d.ts +79 -0
  214. package/lib/trusted-parties/trusted-party2.service.d.ts +114 -0
  215. package/lib/users/profile-details.service.d.ts +21 -0
  216. package/lib/users/profile.gql.d.ts +11 -0
  217. package/lib/users/profile.service.d.ts +35 -0
  218. package/lib/users/profile.types.d.ts +96 -0
  219. package/lib/users/user.gql.d.ts +9 -0
  220. package/lib/users/user.service.d.ts +12 -0
  221. package/lib/users/user.types.d.ts +23 -0
  222. package/lifeready-core.d.ts +9 -0
  223. package/lifeready-core.metadata.json +1 -0
  224. package/package.json +29 -0
  225. package/public-api.d.ts +77 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifeready-core.js","sources":["../../../../projects/core/src/lib/_common/exceptions.ts","../../../../projects/core/src/lib/life-ready.config.ts","../../../../projects/core/src/lib/cryptography/cryptography.types.ts","../../../../projects/core/src/lib/api/time.service.ts","../../../../projects/core/src/lib/cryptography/encryption.service.ts","../../../../projects/core/src/lib/cryptography/web-crypto.service.ts","../../../../projects/core/src/lib/cryptography/key-factory.service.ts","../../../../projects/core/src/lib/api/persist.service.ts","../../../../projects/core/src/lib/cryptography/key.service.ts","../../../../projects/core/src/lib/cryptography/key-graph.service.ts","../../../../projects/core/src/lib/api/lr-apollo.service.ts","../../../../projects/core/src/lib/_common/queries.gql.ts","../../../../projects/core/src/lib/users/profile.gql.ts","../../../../projects/core/src/lib/users/profile.types.ts","../../../../projects/core/src/lib/category/category.gql.ts","../../../../projects/core/src/lib/cryptography/key-meta.service.ts","../../../../projects/core/src/lib/api/contact-card.gql.ts","../../../../projects/core/src/lib/plan/plan.gql.ts","../../../../projects/core/src/lib/plan/plan.service.ts","../../../../projects/core/src/lib/users/profile.service.ts","../../../../projects/core/src/lib/auth/auth.types.ts","../../../../projects/core/src/lib/_common/ast.ts","../../../../projects/core/src/lib/auth/auth.gql.ts","../../../../projects/core/src/lib/auth/idle.types.ts","../../../../projects/core/src/lib/auth/idle.service.ts","../../../../projects/core/src/lib/auth/password.service.ts","../../../../projects/core/src/lib/trusted-parties/tp-password-reset.gql.ts","../../../../projects/core/src/lib/_common/utils.ts","../../../../projects/core/src/lib/_common/run-outside-angular.ts","../../../../projects/core/src/lib/api/query-processor/common-processors.service.ts","../../../../projects/core/src/lib/api/query-processor/tp-password-reset-processor.service.ts","../../../../projects/core/src/lib/api/query-processor/query-processor.service.ts","../../../../projects/core/src/lib/_common/deferred-promise.ts","../../../../projects/core/src/lib/api/lr-graphql/lr-mutation-base.ts","../../../../projects/core/src/lib/api/lr-graphql/lr-mutation.ts","../../../../projects/core/src/lib/api/lr-graphql/lr-merged-mutation.ts","../../../../projects/core/src/lib/api/lr-graphql/lr-graphql.service.ts","../../../../projects/core/src/lib/api/lr-graphql/lr.service.ts","../../../../projects/core/src/lib/auth/life-ready-auth.service.ts","../../../../projects/core/src/lib/api/file.service.ts","../../../../projects/core/src/lib/users/user.gql.ts","../../../../projects/core/src/lib/users/user.service.ts","../../../../projects/core/src/lib/api/key-exchange.gql.ts","../../../../projects/core/src/lib/api/key-exchange.types.ts","../../../../projects/core/src/lib/api/key-exchange.service.ts","../../../../projects/core/src/lib/api/message.service.ts","../../../../projects/core/src/lib/auth/auth.config.ts","../../../../projects/core/src/lib/auth/lbop.service.ts","../../../../projects/core/src/lib/auth/register.service.ts","../../../../projects/core/src/lib/auth/two-factor.service.ts","../../../../projects/core/src/lib/cryptography/slip39.service.ts","../../../../projects/core/src/lib/record/record.gql.ts","../../../../projects/core/src/lib/category/category.types.ts","../../../../projects/core/src/lib/category/category.service.ts","../../../../projects/core/src/lib/category/category-meta.service.ts","../../../../projects/core/src/lib/record/record-attachment.service.ts","../../../../projects/core/src/lib/record/record.types.ts","../../../../projects/core/src/lib/record/record.service.ts","../../../../projects/core/src/lib/record-type/record-type.types.ts","../../../../projects/core/src/lib/record-type/record-type.service.ts","../../../../projects/core/src/lib/trusted-parties/trusted-party.types.ts","../../../../projects/core/src/lib/api/shared-contact-card.service.ts","../../../../projects/core/src/lib/trusted-parties/trusted-party.gql.ts","../../../../projects/core/src/lib/trusted-parties/trusted-party.service.ts","../../../../projects/core/src/lib/scenario/scenario.types.ts","../../../../projects/core/src/lib/scenario/claimants/scenario-claimant.gql.ts","../../../../projects/core/src/lib/scenario/receivers/scenario-receiver.gql.ts","../../../../projects/core/src/lib/scenario/approvals/scenario-approval.gql.ts","../../../../projects/core/src/lib/scenario/scenario.gql.ts","../../../../projects/core/src/lib/scenario/approvals/scenario-approver.service.ts","../../../../projects/core/src/lib/scenario/claimants/scenario-claimant.service.ts","../../../../projects/core/src/lib/scenario/receivers/scenario-receiver.service.ts","../../../../projects/core/src/lib/scenario/scenario.service.ts","../../../../projects/core/src/lib/scenario/scenario-setup.service.ts","../../../../projects/core/src/lib/users/profile-details.service.ts","../../../../projects/core/src/lib/users/user.types.ts","../../../../projects/core/src/lib/life-ready.module.ts","../../../../projects/core/src/lib/plan/plan.types.ts","../../../../projects/core/src/lib/search/search.types.ts","../../../../projects/core/src/lib/search/search.gql.ts","../../../../projects/core/src/lib/search/search.service.ts","../../../../projects/core/src/lib/api/contact-card2.gql.ts","../../../../projects/core/src/lib/api/contact-card2.service.ts","../../../../projects/core/src/lib/api/item2.gql.ts","../../../../projects/core/src/lib/api/item2.service.ts","../../../../projects/core/src/lib/api/key-exchange2.gql.ts","../../../../projects/core/src/lib/api/key-exchange2.service.ts","../../../../projects/core/src/lib/api/shared-contact-card2.gql.ts","../../../../projects/core/src/lib/api/shared-contact-card2.service.ts","../../../../projects/core/src/lib/api/lock.gql.ts","../../../../projects/core/src/lib/api/lock.service.ts","../../../../projects/core/src/lib/trusted-parties/trusted-party2.gql.ts","../../../../projects/core/src/lib/trusted-parties/trusted-party2.service.ts","../../../../projects/core/src/lib/trusted-parties/tp-password-reset.service.ts","../../../../projects/core/src/lib/api/types/graphql.types.ts","../../../../projects/core/src/lib/api/types/lr-graphql.types.ts","../../../../projects/core/src/lib/trusted-parties/tp-password-reset-user.service.ts","../../../../projects/core/src/lib/trusted-parties/tp-password-reset-request.service.ts","../../../../projects/core/src/public-api.ts","../../../../projects/core/src/lifeready-core.ts"],"sourcesContent":["import { GraphQLError } from 'graphql';\r\nimport { debuglog } from 'util';\r\n\r\nexport function handleApolloError(errors: ReadonlyArray<GraphQLError>) {\r\n if (!errors || !errors.length) return;\r\n\r\n const lrErrors = errors.map((x) => ({\r\n code: x.extensions && x.extensions.code,\r\n source: x.extensions && x.extensions.source,\r\n message: x.message,\r\n debug: {\r\n locations: x.locations as any,\r\n path: x.path as string[],\r\n },\r\n }));\r\n\r\n throw new LrException(...lrErrors);\r\n}\r\n\r\nexport class LrError {\r\n code?: string;\r\n source?: string;\r\n message: string;\r\n debug?: {\r\n locations: {\r\n line: number;\r\n column: number;\r\n }[];\r\n path: string[];\r\n };\r\n}\r\n\r\nexport class LrException {\r\n public errors: LrError[];\r\n\r\n constructor(...errors: LrError[]) {\r\n this.errors = errors;\r\n }\r\n\r\n public toString() {\r\n return this.errors.map((t) => JSON.stringify(t, null, 2));\r\n }\r\n}\r\n\r\nexport enum LrApiErrorCode {\r\n ARCHIVED_RESOURCE = 'ARCHIVED_RESOURCE',\r\n BAD_ARGUMENT = 'BAD_ARGUMENT',\r\n BAD_SIGNATURE = 'BAD_SIGNATURE',\r\n BAD_STATE = 'BAD_STATE',\r\n CHANGED_PERMISSIONS = 'CHANGED_PERMISSIONS',\r\n CONCURRENT_ACCESS = 'CONCURRENT_ACCESS',\r\n CONFIG_ERROR = 'CONFIG_ERROR',\r\n CYCLE_DETECTED = 'CYCLE_DETECTED',\r\n EXPIRED = 'EXPIRED',\r\n INVALID_TOKEN = 'INVALID_TOKEN',\r\n INTERNAL_ERROR = 'INTERNAL_ERROR',\r\n JSON_DECODE_ERROR = 'JSON_DECODE_ERROR',\r\n KEY_MISMATCH = 'KEY_MISMATCH',\r\n LIMIT_REACHED = 'LIMIT_REACHED',\r\n LOCKED = 'LOCKED',\r\n LOGIC_ERROR = 'LOGIC_ERROR',\r\n LR_DEBUG_ONLY = 'LR_DEBUG_ONLY',\r\n MIN_DELAY = 'MIN_DELAY',\r\n MISSING_FIELD = 'MISSING_FIELD',\r\n MISSING_FIELD_VALUE = 'MISSING_FIELD_VALUE',\r\n MISSING_QUERY_PARAM = 'MISSING_QUERY_PARAM',\r\n NOT_IMPLEMENTED = 'NOT_IMPLEMENTED',\r\n OBJECT_DOES_NOT_EXIST = 'OBJECT_DOES_NOT_EXIST',\r\n OBJECT_EXISTS = 'OBJECT_EXISTS',\r\n RANGE_ERROR = 'RANGE_ERROR',\r\n TRUSTED_PARTY_NOT_FOUND = 'TRUSTED_PARTY_NOT_FOUND',\r\n UNAUTHENTICATED_USER = 'UNAUTHENTICATED_USER',\r\n USER_NOT_FOUND = 'USER_NOT_FOUND',\r\n VERSION_MISMATCH = 'VERSION_MISMATCH',\r\n WRONG_PERMISSIONS = 'WRONG_PERMISSIONS',\r\n}\r\n\r\nexport enum LrErrorCode {\r\n BadTimeSync = 'LrBadTimeSync',\r\n ReceiveClaimMismatch = 'LrReceiveClaimMismatch',\r\n BadState = 'LrBadState',\r\n BadSignature = 'LrBadSignature',\r\n Auth = 'LrAuth',\r\n BadArgument = 'LrBadArgument',\r\n SuspiciousException = 'LrSuspiciousException',\r\n NotFound = 'LrNotFound',\r\n BadLogic = 'LrBadLogicException',\r\n CodeMismatch = 'LrCodeMismatchException',\r\n ConcurrentAccess = 'LrConcurrentAccessException',\r\n BadRequest = 'LrBadRequestException',\r\n Encryption = 'LrEncryptionGoBad',\r\n Locked = 'LrLockedException',\r\n}\r\n\r\nexport class LrBadArgumentException extends LrException {\r\n constructor(message) {\r\n super({ code: LrErrorCode.BadArgument, message });\r\n }\r\n}\r\n\r\nexport class LrSuspiciousException extends LrException {\r\n constructor(message) {\r\n super({ code: LrErrorCode.BadArgument, message });\r\n }\r\n}\r\n\r\nexport class LrNotFoundException extends LrException {\r\n constructor(message) {\r\n super({ code: LrErrorCode.NotFound, message });\r\n }\r\n}\r\n\r\nexport class LrBadLogicException extends LrException {\r\n constructor(message) {\r\n super({ code: LrErrorCode.BadLogic, message });\r\n }\r\n}\r\n\r\nexport class LrCodeMismatchException extends LrException {\r\n constructor(message) {\r\n super({ code: LrErrorCode.CodeMismatch, message });\r\n }\r\n}\r\n\r\nexport class LrConcurrentAccessException extends LrException {\r\n constructor(message) {\r\n super({ code: LrErrorCode.ConcurrentAccess, message });\r\n }\r\n}\r\n\r\nexport class LrLockedException extends LrException {\r\n constructor(message) {\r\n super({ code: LrErrorCode.Locked, message });\r\n }\r\n}\r\n\r\nexport class LrBadRequestException extends LrException {\r\n constructor(message) {\r\n super({ code: LrErrorCode.BadRequest, message });\r\n }\r\n}\r\n\r\nexport class LrAuthException extends LrException {\r\n constructor(message) {\r\n super({ code: LrErrorCode.Auth, message });\r\n }\r\n}\r\n\r\nexport class LrEncryptionException extends LrException {\r\n constructor(message) {\r\n super({ code: LrErrorCode.Encryption, message });\r\n }\r\n}\r\n\r\nexport class LrUnsupportedException extends LrException {\r\n constructor(message) {\r\n super({\r\n code: 'LrUnsupportedException',\r\n message,\r\n });\r\n }\r\n}\r\n\r\nexport class LrExpiredCodeException extends LrException {\r\n constructor(message) {\r\n super({\r\n code: 'LrExpiredCodeException',\r\n message,\r\n });\r\n }\r\n}\r\n\r\nexport class LrExpiredException extends LrException {\r\n constructor(message) {\r\n super({\r\n code: 'LrExpiredException',\r\n message,\r\n });\r\n }\r\n}\r\n\r\nexport class LrBadStateException extends LrException {\r\n constructor(message) {\r\n super({\r\n code: 'LrBadStateException',\r\n message,\r\n });\r\n }\r\n}\r\n","import { InjectionToken } from '@angular/core';\r\nimport { AuthClass } from '@aws-amplify/auth/lib-esm/Auth';\r\nimport {\r\n ApolloClientOptions,\r\n ApolloLink,\r\n createHttpLink,\r\n DefaultOptions,\r\n from,\r\n InMemoryCache,\r\n} from '@apollo/client/core';\r\nimport { setContext } from '@apollo/client/link/context';\r\nimport { RetryLink } from '@apollo/client/link/retry';\r\nimport { LrApiErrorCode } from './_common/exceptions';\r\nimport { GraphQLError } from 'graphql';\r\n\r\nexport const LR_CONFIG = new InjectionToken<LifeReadyConfig>('LR.AUTH');\r\nconst RETRY_ERROR_CODES = [LrApiErrorCode.CONCURRENT_ACCESS];\r\n\r\nexport interface LifeReadyConfig {\r\n authUrl: string;\r\n apiUrl: string;\r\n apolloUrl: string;\r\n userPoolId: string;\r\n userPoolWebClientId: string;\r\n apolloConfig?: ApolloClientOptions<any>;\r\n // Mainly to allow localhost to not needing this. Default to falsy\r\n disableSessionEncryptionKey?: boolean;\r\n}\r\n\r\nexport const configureApollo = (\r\n config: LifeReadyConfig,\r\n auth: AuthClass\r\n): ApolloClientOptions<any> => {\r\n const defaultOptions: DefaultOptions = {\r\n watchQuery: {\r\n fetchPolicy: 'no-cache',\r\n errorPolicy: 'all',\r\n },\r\n query: {\r\n fetchPolicy: 'no-cache',\r\n errorPolicy: 'all',\r\n },\r\n mutate: {\r\n errorPolicy: 'all',\r\n },\r\n };\r\n\r\n const authLink = setContext(async (_, { headers }) => {\r\n let accessJwt = null;\r\n try {\r\n accessJwt = (await auth.currentSession()).getAccessToken();\r\n } catch {\r\n console.log('User not signed in');\r\n }\r\n\r\n return {\r\n headers: {\r\n ...headers,\r\n authorization: accessJwt ? `Bearer ${accessJwt.jwtToken}` : '',\r\n },\r\n };\r\n });\r\n\r\n // We are only retrying on certain errors, like the CONCURRENT_ACCESS gql\r\n // error which indicates DB race condition. So can be safely retried.\r\n const retryIf = (error, _) => {\r\n // The RetryLink is called on network error as well, so we need to filter for GraphQL errors.\r\n if (error instanceof GraphQLErrorException) {\r\n if (\r\n error.errors.some((e) => RETRY_ERROR_CODES.includes(e.extensions?.code))\r\n ) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n };\r\n\r\n const retryLink = new RetryLink({\r\n delay: {\r\n initial: 300,\r\n max: Infinity,\r\n jitter: true,\r\n },\r\n attempts: {\r\n max: 3,\r\n retryIf,\r\n },\r\n });\r\n\r\n class GraphQLErrorException extends Error {\r\n constructor(public errors: readonly GraphQLError[]) {\r\n super(errors.map((e) => e.message).join(', '));\r\n }\r\n }\r\n\r\n // Throw exception on gql errors which effectively promotes it to a network\r\n // error, which can then be handled by the RetryLink.\r\n const promoteGqlErrors = new ApolloLink((operation, forward) => {\r\n return forward(operation).map((data) => {\r\n if (data && data.errors) {\r\n const errors = data.errors.filter((e) =>\r\n RETRY_ERROR_CODES.includes(e.extensions?.code)\r\n );\r\n\r\n if (errors.length > 0) {\r\n throw new GraphQLErrorException(data.errors);\r\n }\r\n }\r\n return data;\r\n });\r\n });\r\n\r\n const httpLink = createHttpLink({\r\n uri: config.apolloUrl,\r\n // Sending the sessionid cookie so that the server can use session data when needed.\r\n // eg. setting the session encryption key.\r\n credentials: 'include',\r\n });\r\n\r\n return {\r\n link: from([retryLink, promoteGqlErrors, authLink, httpLink]),\r\n cache: new InMemoryCache(),\r\n defaultOptions,\r\n ...config.apolloConfig,\r\n };\r\n};\r\n","import { JWK } from 'node-jose';\r\n\r\nexport interface Key {\r\n id: string;\r\n pbk?: string;\r\n jwk?: JWK.Key;\r\n}\r\n\r\nexport interface PassKeyParams {\r\n kid: string;\r\n salt: string;\r\n iterations: number;\r\n}\r\n\r\nexport interface PassIdpParams {\r\n salt: string;\r\n iterations: number;\r\n}\r\n\r\nexport interface LbopKeyParams {\r\n kid: string;\r\n salt: string;\r\n iterations: number;\r\n}\r\n\r\nexport interface PassIdpVerifier {\r\n wrappedPrK: object;\r\n pbk: object;\r\n}\r\n\r\nexport interface LbopKeyVerifier {\r\n wrappedKey: object;\r\n key: object;\r\n}\r\n\r\nexport interface PassKey {\r\n id: string;\r\n passKeyParams?: PassKeyParams;\r\n passIdpParams?: PassIdpParams;\r\n wrappedPassIdpVerifierPrk?: object;\r\n created?: string;\r\n}\r\n\r\nexport interface KeyLink {\r\n keyId: string;\r\n wrappingKeyId: string;\r\n wrappedKey: string; // JWE json string\r\n}\r\n\r\nexport interface PassKeyLink {\r\n keyId: string;\r\n passKeyId: string;\r\n wrappedKey: string; // JWE json string\r\n}\r\n\r\nexport enum NodeType {\r\n Key = 'key',\r\n PassKey = 'passKey',\r\n}\r\n\r\nexport interface Node {\r\n type: NodeType;\r\n data: Key | PassKey;\r\n}\r\n\r\nexport enum EdgeType {\r\n KeyLink = 'keyLink',\r\n PassKeyLink = 'passKeyLink',\r\n}\r\n\r\nexport interface Edge {\r\n type: EdgeType;\r\n data: KeyLink | PassKeyLink;\r\n}\r\n\r\nexport interface KeyGraphResponse {\r\n keys?: Key[];\r\n keyLinks?: KeyLink[];\r\n passKeys?: PassKey[];\r\n passKeyLinks?: PassKeyLink[];\r\n}\r\n\r\nexport interface HasKeyGraph {\r\n // The name of the keyGraph field returned from both queries and mutations are the same\r\n keyGraph?: KeyGraphResponse;\r\n}\r\n\r\n// export enum PayloadType {\r\n// JSON = 'JSON',\r\n// ArrayBuffer = 'ArrayBuffer',\r\n// }\r\nexport type PayloadType = 'json' | 'ArrayBuffer';\r\n\r\nexport interface DeriveKeyResult {\r\n jwk: JWK.Key;\r\n}\r\n\r\nexport interface DerivePassIdpParams extends PassIdpParams {\r\n password: string;\r\n}\r\n\r\nexport interface DerivePassKeyParams extends PassKeyParams {\r\n password: string;\r\n}\r\n\r\nexport interface DeriveLbopKeyParams extends PassKeyParams {\r\n password: string;\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport { AuthClass } from '@aws-amplify/auth/lib-esm/Auth';\r\nimport { Apollo } from 'apollo-angular';\r\nimport gql from 'graphql-tag';\r\nimport * as moment_ from 'moment';\r\nimport {\r\n LrErrorCode,\r\n LrException,\r\n handleApolloError,\r\n} from '../_common/exceptions';\r\n// \"why?\" you ask: https://stackoverflow.com/questions/59735280/angular-8-moment-error-cannot-call-a-namespace-moment\r\nconst moment = moment_;\r\n\r\nexport const ServerTimeQuery = gql`\r\n query {\r\n serverTime {\r\n timestamp\r\n }\r\n }\r\n`;\r\n\r\ninterface ServerTime {\r\n timestamp: string;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class TimeService {\r\n public VERIFY_ENABLED = true;\r\n private readonly MAX_DIFF_MSEC = moment\r\n .duration({ seconds: 30 })\r\n .asMilliseconds();\r\n\r\n offsetMs: number = null; // Millisecond offset of local clock.\r\n verified = false; // Verified with independent time source\r\n\r\n constructor(private auth: AuthClass, private apollo: Apollo) {}\r\n\r\n private async getAccessToken(): Promise<string> {\r\n try {\r\n return (await this.auth.currentAuthenticatedUser())\r\n .getSignInUserSession()\r\n .getAccessToken()\r\n .getJwtToken();\r\n } catch (error) {\r\n return ''; // Not authenticated\r\n }\r\n }\r\n\r\n // Get time from independent source to confirm.\r\n private async verifyCognito(): Promise<void> {\r\n const accessToken = await this.getAccessToken();\r\n if (!accessToken) {\r\n return;\r\n }\r\n\r\n // Request headers from AWS Amplify Auth lib\r\n // accept: */*\r\n // accept-encoding: gzip, deflate, br\r\n // accept-language: en-GB,en-US;q=0.9,en;q=0.8\r\n // cache-control: no-cache\r\n // content-length: 1089\r\n // content-type: application/x-amz-json-1.1\r\n // origin: http://localhost:4200\r\n // pragma: no-cache\r\n // referer: http://localhost:4200/\r\n // sec-fetch-dest: empty\r\n // sec-fetch-mode: cors\r\n // sec-fetch-site: cross-site\r\n // user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36\r\n // x-amz-target: AWSCognitoIdentityProviderService.GetUser\r\n // x-amz-user-agent: aws-amplify/0.1.x js\r\n\r\n // We are only interested in the Date field.\r\n // AZ: I suppose we could use any end-point that provides a reliable Date field in the header. And we don't\r\n // need to be authenticated. Even a 400 response would have a Date header. But the worry is that AWS might\r\n // think it's some sort of attack, and block the IP or domain. At least in an authenticated call it can't be\r\n // seen as illegitimate.\r\n const response = await fetch(\r\n 'https://cognito-idp.ap-southeast-2.amazonaws.com/',\r\n {\r\n method: 'POST', // *GET, POST, PUT, DELETE, etc.\r\n mode: 'cors', // no-cors, *cors, same-origin\r\n cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached\r\n headers: {\r\n 'x-amz-target': 'AWSCognitoIdentityProviderService.GetUser',\r\n 'x-amz-user-agent': 'aws-amplify/0.1.x js',\r\n 'Content-Type': 'application/x-amz-json-1.1',\r\n },\r\n // redirect: 'follow', // manual, *follow, error\r\n // referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url\r\n body: JSON.stringify({\r\n AccessToken: accessToken,\r\n }), // body data type must match \"Content-Type\" header\r\n }\r\n );\r\n\r\n const now = Date.now();\r\n\r\n const verifyTime = moment(response.headers.get('Date')).valueOf();\r\n const serverTime = now + this.offsetMs;\r\n const diff = Math.abs(serverTime - verifyTime);\r\n\r\n if (diff > this.MAX_DIFF_MSEC) {\r\n throw new LrException({\r\n code: LrErrorCode.BadTimeSync,\r\n message: `Server time does not match independent source. ServerTime: ${serverTime}, Cognito time: ${verifyTime}`,\r\n });\r\n }\r\n\r\n this.verified = true;\r\n }\r\n\r\n private async refresh(): Promise<void> {\r\n const start = Date.now();\r\n const res = await this.apollo\r\n .query<{ serverTime: ServerTime }>({ query: ServerTimeQuery })\r\n .toPromise();\r\n const end = Date.now();\r\n\r\n handleApolloError(res.errors);\r\n\r\n const serverTime = parseInt(res.data.serverTime.timestamp, 10);\r\n\r\n const roundtrip = end - start;\r\n this.offsetMs = serverTime - (start + roundtrip / 2);\r\n\r\n if (this.VERIFY_ENABLED) {\r\n await this.verifyCognito();\r\n }\r\n }\r\n\r\n async serverNow(): Promise<number> {\r\n let needsRefresh = false;\r\n\r\n // First call\r\n if (this.offsetMs === null) {\r\n needsRefresh = true;\r\n }\r\n\r\n if (this.VERIFY_ENABLED) {\r\n // logged in but not yet verified time matches.\r\n if (!this.verified && (await this.getAccessToken())) {\r\n needsRefresh = true;\r\n }\r\n }\r\n\r\n if (needsRefresh) {\r\n await this.refresh();\r\n }\r\n\r\n return Date.now() + this.offsetMs;\r\n }\r\n}\r\n","import {\r\n LrException,\r\n LrErrorCode,\r\n LrBadArgumentException,\r\n} from './../_common/exceptions';\r\nimport { ComponentFactoryResolver, Injectable } from '@angular/core';\r\nimport { JWE, JWK, JWS, util } from 'node-jose';\r\nimport { Key, PayloadType } from './cryptography.types';\r\nimport { TimeService } from '../api/time.service';\r\n\r\nexport enum JoseSerialization {\r\n JSON = 'JSON',\r\n COMPACT = 'COMPACT',\r\n}\r\n\r\nexport interface VerifyOptions {\r\n payloadType?: PayloadType;\r\n returnOnlyPayload?: boolean; // If true, return only the decoded payload.\r\n}\r\n\r\nexport interface DecryptOptions {\r\n payloadType?: PayloadType;\r\n returnOnlyPayload?: boolean; // If true, return only the decoded payload.\r\n serializations?: JoseSerialization[];\r\n}\r\n\r\nexport const VERIFY_OPTIONS_DEFAULT: VerifyOptions = {\r\n payloadType: 'json',\r\n returnOnlyPayload: true,\r\n};\r\n\r\nexport const DECRYPT_OPTIONS_DEFAULT: DecryptOptions = {\r\n payloadType: 'json',\r\n returnOnlyPayload: true,\r\n serializations: [JoseSerialization.JSON],\r\n};\r\n\r\nexport function isSymmetricKey(key: JWK.Key) {\r\n // TODO: make sure this covers all cases.\r\n return key.kty === 'oct';\r\n}\r\n\r\nexport function asJwk(key: JWK.Key | Key | any): JWK.Key | null {\r\n // TODO: make sure this covers all cases.\r\n // Excluded:\r\n // key.use - only for public keys, Ref: https://tools.ietf.org/html/rfc7517#section-4.2\r\n\r\n if (key.id && key.jwk) {\r\n return key.jwk;\r\n } else if (key.keystore && key.length && key.kty && key.kid && key.alg) {\r\n return key;\r\n } else {\r\n return null;\r\n }\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class EncryptionService {\r\n constructor(private timeService: TimeService) {}\r\n\r\n async decrypt(\r\n key: JWK.Key | Key, // string is assumed to be key.id, will unwrap key.\r\n jwe: object | string, // string will be JSON.parsed\r\n options?: DecryptOptions\r\n ): Promise<JWE.DecryptResult | any> {\r\n const opt = {\r\n algorithms: ['dir', 'A*GCM', 'RSA-OAEP-*'],\r\n };\r\n\r\n options = {\r\n ...DECRYPT_OPTIONS_DEFAULT,\r\n ...options,\r\n };\r\n\r\n if ((key as Key).jwk) {\r\n key = (key as Key).jwk;\r\n }\r\n\r\n if (typeof jwe === 'string') {\r\n if (options.serializations.includes(JoseSerialization.JSON)) {\r\n try {\r\n jwe = JSON.parse(jwe);\r\n } catch (error) {\r\n if (options.serializations.includes(JoseSerialization.COMPACT)) {\r\n console.log(\r\n 'Not a JSON-formatted JWE, it maybe compact serialisation format.'\r\n );\r\n } else {\r\n throw error;\r\n }\r\n }\r\n }\r\n }\r\n\r\n // {result} is a Object with:\r\n // * header: the combined 'protected' and 'unprotected' header members\r\n // * protected: an array of the member names from the \"protected\" member\r\n // * key: Key used to decrypt\r\n // * payload: Buffer of the decrypted content\r\n // * plaintext: Buffer of the decrypted content (alternate), just a reference to payload\r\n const res = await JWE.createDecrypt(key as JWK.Key, opt).decrypt(\r\n jwe as any\r\n );\r\n\r\n res.payload = this.decodePayload(options.payloadType, res.payload);\r\n\r\n if (options.returnOnlyPayload) {\r\n return res.payload;\r\n } else {\r\n return res;\r\n }\r\n }\r\n\r\n // TODO rename this to encrypt() and use as the most common usecase\r\n async encryptToString(\r\n key: JWK.Key,\r\n content: ArrayBuffer | string | object\r\n ): Promise<string> {\r\n return JSON.stringify(await this.encrypt(key, content));\r\n }\r\n\r\n // TODO rename this to encryptToJSON() and use this when required.\r\n async encrypt(\r\n key: JWK.Key,\r\n content: ArrayBuffer | string | object\r\n ): Promise<any> {\r\n if (!content) {\r\n throw new Error('Encrypting empty content.');\r\n }\r\n\r\n if (!(content instanceof ArrayBuffer)) {\r\n content = new TextEncoder().encode(JSON.stringify(content));\r\n }\r\n\r\n return JWE.createEncrypt(\r\n {\r\n contentAlg: 'A256GCM',\r\n fields: {\r\n timestamp: await this.timeService.serverNow(),\r\n },\r\n } as any,\r\n key\r\n )\r\n .update(content)\r\n .final() as any;\r\n }\r\n\r\n // <AZ> Unlike signContent, the serialised \"content\" variable is contained inside\r\n // the result. So ordering of fields within \"content\" is not an issue.\r\n async sign(key: JWK.Key, content: Buffer | string | object): Promise<any> {\r\n const signer = JWS.createSign(\r\n {\r\n fields: {\r\n timestamp: await this.timeService.serverNow(),\r\n },\r\n },\r\n key\r\n );\r\n\r\n if (content instanceof Buffer) {\r\n signer.update(content);\r\n } else {\r\n signer.update(JSON.stringify(content), 'utf8');\r\n }\r\n\r\n return signer.final();\r\n }\r\n\r\n async signToString(\r\n key: JWK.Key,\r\n content: Buffer | string | object\r\n ): Promise<string> {\r\n return JSON.stringify(await this.sign(key, content));\r\n }\r\n\r\n async verify(\r\n key: JWK.Key,\r\n jws: object,\r\n options?: VerifyOptions\r\n ): Promise<any> {\r\n const opt = {\r\n algorithms: ['RS*'],\r\n };\r\n\r\n options = {\r\n ...VERIFY_OPTIONS_DEFAULT,\r\n ...options,\r\n };\r\n\r\n try {\r\n const res = await JWS.createVerify(key, opt).verify(jws as any);\r\n\r\n res.payload = this.decodePayload(options.payloadType, res.payload);\r\n\r\n if (options.returnOnlyPayload) {\r\n return res.payload;\r\n } else {\r\n return res;\r\n }\r\n } catch (error) {\r\n throw new LrException({\r\n code: LrErrorCode.BadSignature,\r\n message: `Bad signature: ${error}`,\r\n });\r\n }\r\n }\r\n\r\n async encryptThenSign(\r\n {\r\n key,\r\n sigPrk,\r\n }: {\r\n key: JWK.Key;\r\n sigPrk: JWK.Key;\r\n },\r\n content: ArrayBuffer | string | object\r\n ): Promise<{ cipher: string; sig: string }> {\r\n const cipher = JSON.stringify(await this.encrypt(key, content));\r\n const sig = await this.sign(sigPrk, cipher);\r\n delete sig.payload;\r\n\r\n return {\r\n cipher,\r\n sig: JSON.stringify(sig),\r\n };\r\n }\r\n\r\n private decodePayload(\r\n payloadType: PayloadType,\r\n payload: ArrayBuffer\r\n ): ArrayBuffer | any {\r\n switch (payloadType) {\r\n case 'json':\r\n return JSON.parse(new TextDecoder().decode(payload));\r\n case 'ArrayBuffer':\r\n return payload;\r\n default:\r\n throw new LrBadArgumentException(`Unknown payloadType: ${payloadType}`);\r\n }\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class WebCryptoService {\r\n crypto: Crypto = window.crypto;\r\n\r\n toHex(buffer: ArrayBuffer) {\r\n // Ref: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest\r\n const array = Array.from(new Uint8Array(buffer)); // convert buffer to byte array\r\n const hex = array.map((b) => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string\r\n return hex;\r\n }\r\n\r\n async stringDigest(algorithm: string, message: string): Promise<string> {\r\n const encoder = new TextEncoder();\r\n const data = encoder.encode(message);\r\n const hash = await this.crypto.subtle.digest(algorithm, data);\r\n return this.toHex(hash);\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport { JWK } from 'node-jose';\r\nimport {\r\n LbopKeyParams,\r\n PassIdpParams,\r\n PassKeyParams,\r\n DeriveKeyResult,\r\n DerivePassIdpParams,\r\n DerivePassKeyParams,\r\n DeriveLbopKeyParams,\r\n} from './cryptography.types';\r\nimport { WebCryptoService } from './web-crypto.service';\r\nimport {\r\n LrBadArgumentException,\r\n LrSuspiciousException,\r\n} from '../_common/exceptions';\r\n\r\nexport async function sha256(message) {\r\n // encode as UTF-8\r\n const msgBuffer = new TextEncoder().encode(message);\r\n\r\n // hash the message\r\n const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);\r\n\r\n // convert ArrayBuffer to Array\r\n const hashArray = Array.from(new Uint8Array(hashBuffer));\r\n\r\n // convert bytes to hex string\r\n const hashHex = hashArray\r\n .map((b) => ('00' + b.toString(16)).slice(-2))\r\n .join('');\r\n return hashHex;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class KeyFactoryService {\r\n constructor(private webCryptoService: WebCryptoService) {\r\n this.crypto = this.webCryptoService.crypto;\r\n }\r\n private readonly crypto;\r\n // Global keys store. Otherwise, each call to asKey creates a new keyStore.\r\n // <AZ> Did not seem to improve speed.\r\n // public static keyStore = JWK.createKeyStore();\r\n\r\n // AZ: This can't be change easily. It's basically a PassK or PassIdp rotation.\r\n // todo: we should eventually increase this periodically to match with Moore's law.\r\n // The iterations for each key are kept by the server as well but we assume the value\r\n // from the server is not trustworthy, so need to have minimum thresholds here.\r\n // If creating new keys, these minimum are used.\r\n public readonly MIN_PASS_IDP_PBKDF_ITER = 100000;\r\n public readonly MIN_PASS_KEY_PBKDF_ITER = 100000;\r\n public readonly MIN_LBOP_KEY_PBKDF_ITER = 100000;\r\n\r\n // These are used as the default values. They must be larger than the minimum values.\r\n public readonly DEFAULT_PASS_IDP_PBKDF_ITER = this.MIN_PASS_IDP_PBKDF_ITER;\r\n public readonly DEFAULT_PASS_KEY_PBKDF_ITER = this.MIN_PASS_KEY_PBKDF_ITER;\r\n public readonly DEFAULT_LBOP_KEY_PBKDF_ITER = this.MIN_LBOP_KEY_PBKDF_ITER;\r\n\r\n static asKey(\r\n key: string | Buffer | object | JWK.RawKey,\r\n form?:\r\n | 'json'\r\n | 'private'\r\n | 'pkcs8'\r\n | 'public'\r\n | 'spki'\r\n | 'pkix'\r\n | 'x509'\r\n | 'pem',\r\n extras?: Record<string, unknown>\r\n ): Promise<JWK.Key> {\r\n // <AZ> Using a single global key store did not seem to improve speed.\r\n // return KeyFactoryService.keyStore.add(key, form, extras);\r\n return JWK.asKey(key, form, extras);\r\n }\r\n\r\n randomString(digits: number): string {\r\n if (digits <= 0) {\r\n throw new LrBadArgumentException('digits <= 0');\r\n }\r\n const validChars =\r\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\r\n let array = new Uint32Array(digits);\r\n this.crypto.getRandomValues(array);\r\n array = array.map((x) => validChars.charCodeAt(x % validChars.length));\r\n return String.fromCharCode.apply(null, array);\r\n }\r\n\r\n randomDigitsNoZeros(digits: number): string {\r\n return this.randomChoices([1, 2, 3, 4, 5, 6, 7, 8, 9], digits).join('');\r\n }\r\n\r\n randomChoices<T>(array: T[], chooseN: number): T[] {\r\n if (array.length <= 1) {\r\n throw new LrBadArgumentException('array.length <= 0');\r\n }\r\n if (chooseN <= 0) {\r\n throw new LrBadArgumentException('chooseN <= 0');\r\n }\r\n const values = new Uint32Array(chooseN);\r\n this.crypto.getRandomValues(values);\r\n const ret: T[] = [];\r\n values.forEach((v) => ret.push(array[v % array.length]));\r\n return ret;\r\n }\r\n\r\n createSalt(): string {\r\n return this.randomString(16);\r\n }\r\n\r\n async createKey(): Promise<JWK.Key> {\r\n const key = await this.crypto.subtle.generateKey(\r\n {\r\n name: 'AES-GCM',\r\n length: 256, // can be 128, 192, or 256\r\n },\r\n true, // whether the key is extractable (i.e. can be used in exportKey)\r\n ['encrypt', 'decrypt'] // must be [\"encrypt\", \"decrypt\"] or [\"wrapKey\", \"unwrapKey\"]\r\n );\r\n\r\n const jwk = await this.crypto.subtle.exportKey('jwk', key);\r\n\r\n // Removing the fields not needed by node-jose\r\n delete jwk.ext;\r\n delete jwk.key_ops;\r\n\r\n return KeyFactoryService.asKey(jwk);\r\n }\r\n\r\n async createSignKey(): Promise<JWK.Key> {\r\n const key = await this.crypto.subtle.generateKey(\r\n {\r\n name: 'HMAC',\r\n hash: { name: 'SHA-512' },\r\n },\r\n true,\r\n ['sign', 'verify']\r\n );\r\n\r\n const jwk = await this.crypto.subtle.exportKey('jwk', key);\r\n\r\n // Removing the fields not needed by node-jose\r\n delete jwk.key_ops;\r\n delete jwk.ext;\r\n\r\n return KeyFactoryService.asKey(jwk);\r\n }\r\n\r\n async createPkcKey(): Promise<JWK.Key> {\r\n // node-jose is not using Forge properly. It should be calling the async version of\r\n // pki.rsa.generateKeyPair() with a callback. Instead it calls the sync version. Webcrypto\r\n // does not support sync version, so it uses the javascript implementation, which is way too slow.\r\n // So we generate using webcrypto and import the key.\r\n // Unfortunately Elliptical Curve is not supported by Webcrypto. So we have to settle for RSA.\r\n const key = await this.crypto.subtle.generateKey(\r\n {\r\n name: 'RSA-OAEP',\r\n modulusLength: 2048, // can be 1024, 2048, 3072, 4096 ... 16384\r\n // As per suggestion: https://developer.mozilla.org/en-US/docs/Web/API/RsaHashedKeyGenParams\r\n publicExponent: new Uint8Array([0x01, 0x00, 0x01]),\r\n hash: { name: 'SHA-256' }, // can be \"SHA-1\", \"SHA-256\", \"SHA-384\", or \"SHA-512\"\r\n },\r\n true, // whether the key is extractable (i.e. can be used in exportKey)\r\n ['encrypt', 'decrypt'] // must be [\"encrypt\", \"decrypt\"] or [\"wrapKey\", \"unwrapKey\"]\r\n );\r\n\r\n const jwk = await this.crypto.subtle.exportKey('jwk', key.privateKey);\r\n // Removing the fields not needed by node-jose\r\n delete jwk.key_ops;\r\n delete jwk.ext;\r\n\r\n return KeyFactoryService.asKey(jwk);\r\n }\r\n\r\n async createPkcSignKey(): Promise<JWK.Key> {\r\n const key = await this.crypto.subtle.generateKey(\r\n {\r\n name: 'RSASSA-PKCS1-v1_5',\r\n modulusLength: 2048, // can be 1024, 2048, or 4096\r\n // As per suggestion: https://developer.mozilla.org/en-US/docs/Web/API/RsaHashedKeyGenParams\r\n publicExponent: new Uint8Array([0x01, 0x00, 0x01]),\r\n hash: { name: 'SHA-256' }, // can be \"SHA-1\", \"SHA-256\", \"SHA-384\", or \"SHA-512\"\r\n },\r\n true, // whether the key is extractable (i.e. can be used in exportKey)\r\n ['sign', 'verify'] // can be any combination of \"sign\" and \"verify\"\r\n );\r\n\r\n const jwk = await this.crypto.subtle.exportKey('jwk', key.privateKey);\r\n\r\n // Removing the fields not needed by node-jose\r\n delete jwk.key_ops;\r\n delete jwk.ext;\r\n\r\n return KeyFactoryService.asKey(jwk);\r\n }\r\n\r\n async deriveKey({\r\n password,\r\n salt,\r\n iterations,\r\n kid,\r\n }: {\r\n password: string;\r\n salt: string;\r\n iterations: number;\r\n kid?: string;\r\n }): Promise<DeriveKeyResult> {\r\n const enc = new TextEncoder();\r\n const rawKey = await this.crypto.subtle.importKey(\r\n 'raw',\r\n enc.encode(password),\r\n 'PBKDF2',\r\n false,\r\n ['deriveBits', 'deriveKey']\r\n );\r\n\r\n const passKey = await crypto.subtle.deriveKey(\r\n {\r\n name: 'PBKDF2',\r\n salt: new TextEncoder().encode(salt),\r\n iterations,\r\n hash: 'SHA-256',\r\n },\r\n rawKey,\r\n { name: 'AES-GCM', length: 256 },\r\n true,\r\n ['encrypt', 'decrypt']\r\n );\r\n\r\n const passKeyJson: any = await crypto.subtle.exportKey('jwk', passKey);\r\n if (kid) {\r\n passKeyJson.kid = kid;\r\n }\r\n\r\n const jwk = await KeyFactoryService.asKey(passKeyJson);\r\n\r\n return { jwk };\r\n }\r\n\r\n async derivePassIdp(params: DerivePassIdpParams): Promise<DeriveKeyResult> {\r\n if (params.iterations < this.MIN_PASS_IDP_PBKDF_ITER) {\r\n throw new LrSuspiciousException(\r\n `The number of PassIdp key derivation iterations sent from the server (${params.iterations}) is lower than the minimum (${this.MIN_PASS_IDP_PBKDF_ITER})`\r\n );\r\n }\r\n return this.deriveKey(params);\r\n }\r\n\r\n async derivePassKey(params: DerivePassKeyParams): Promise<DeriveKeyResult> {\r\n if (params.iterations < this.MIN_PASS_KEY_PBKDF_ITER) {\r\n throw new LrSuspiciousException(\r\n `The number of PassKey key derivation iterations sent from the server(${params.iterations}) is lower than the minimum(${this.MIN_PASS_KEY_PBKDF_ITER})`\r\n );\r\n }\r\n return this.deriveKey(params);\r\n }\r\n\r\n async deriveLbopKey(params: DeriveLbopKeyParams): Promise<DeriveKeyResult> {\r\n if (params.iterations < this.MIN_LBOP_KEY_PBKDF_ITER) {\r\n throw new LrSuspiciousException(\r\n `The number of LbopKey key derivation iterations sent from the server(${params.iterations}) is lower than the minimum(${this.MIN_LBOP_KEY_PBKDF_ITER})`\r\n );\r\n }\r\n return this.deriveKey(params);\r\n }\r\n\r\n async createKid(): Promise<string> {\r\n // todo: AZ: node-jose source uses node's default UUID() function for kid, so just change to use that.\r\n // for now, we are just creating a new key to use it's kid.\r\n // The kid is a part of the JWK system. LR backend maintains the key hierarchy separately with it's own\r\n // key id. But we just use it here as a double check.\r\n return (await this.createKey()).kid;\r\n }\r\n\r\n async createPassIdpParams(): Promise<PassIdpParams> {\r\n return {\r\n salt: this.createSalt(),\r\n iterations: this.DEFAULT_PASS_IDP_PBKDF_ITER,\r\n };\r\n }\r\n\r\n async createPassKeyParams(): Promise<PassKeyParams> {\r\n return {\r\n salt: this.createSalt(),\r\n kid: await this.createKid(),\r\n iterations: this.DEFAULT_PASS_KEY_PBKDF_ITER,\r\n };\r\n }\r\n\r\n async createLbopKeyParams(): Promise<LbopKeyParams> {\r\n return {\r\n salt: this.createSalt(),\r\n // todo: AZ: node-jose source uses node's default UUID() function for kid, so just change to use that.\r\n // for now, we are just creating a new key to use it's kid.\r\n // The kid is a part of the JWK system. LR backend maintains the key hierarchy separately with it's own\r\n // key id. But we just use it here as a double check.\r\n kid: await this.createKid(),\r\n iterations: this.DEFAULT_PASS_KEY_PBKDF_ITER,\r\n };\r\n }\r\n}\r\n","import { JWK } from 'node-jose';\r\nimport { Injectable, Injector } from '@angular/core';\r\nimport { CookieService } from 'ngx-cookie-service';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { isDevMode } from '@angular/core';\r\nimport { LrBadArgumentException } from '../_common/exceptions';\r\nimport { KeyFactoryService as KFS } from '../cryptography/key-factory.service';\r\n\r\ninterface Item {\r\n data: string;\r\n expiry?: string; // iso format\r\n serverSession?: boolean;\r\n}\r\n\r\ninterface CookieItem {\r\n key: any;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class PersistService {\r\n private readonly KEY_PREFIX = 'lrSession-';\r\n\r\n private cookieSecure = true;\r\n private serverSessionEncryptionKey: JWK.Key = null;\r\n\r\n constructor(\r\n private keyFactory: KFS,\r\n private cookieService: CookieService,\r\n private encryptionService: EncryptionService,\r\n private injector: Injector\r\n ) {\r\n if (isDevMode()) {\r\n this.setCookieSecure(false);\r\n }\r\n }\r\n\r\n setServerSessionEncryptionKey(key: JWK.Key) {\r\n this.serverSessionEncryptionKey = key;\r\n }\r\n\r\n clearServerSessionEncryptionKey() {\r\n this.serverSessionEncryptionKey = null;\r\n }\r\n\r\n // It's important that set and delete cookie use exactly the same set of parameters.\r\n private getCookieParams() {\r\n return {\r\n path: '/',\r\n domain: null, // which means the current domain of the frontend app.\r\n secure: this.cookieSecure,\r\n sameSite: 'Lax' as 'Lax' | 'None' | 'Strict',\r\n };\r\n }\r\n\r\n public clear() {\r\n // Remove all cookies\r\n Object.keys(this.cookieService.getAll()).forEach((key) => {\r\n if (key.startsWith(this.KEY_PREFIX)) {\r\n this.deletePrefixedName(key);\r\n }\r\n });\r\n\r\n // Remove all persisted session variables\r\n Object.keys(localStorage).forEach((key) => {\r\n if (key.startsWith(this.KEY_PREFIX)) {\r\n this.deletePrefixedName(key);\r\n }\r\n });\r\n }\r\n\r\n public setCookieSecure(value: boolean) {\r\n this.cookieSecure = value;\r\n if (!value) {\r\n if (isDevMode()) {\r\n console.warn(\r\n 'The cookie secure flag in persistService has been set to false, set it to true in production mode'\r\n );\r\n } else {\r\n throw new LrBadArgumentException(\r\n 'Can not set PersistService cookie secure flag to false in production mode.'\r\n );\r\n }\r\n }\r\n }\r\n\r\n private prefixName(name: string): string {\r\n return this.KEY_PREFIX + name;\r\n }\r\n\r\n public delete(name: string): void {\r\n this.deletePrefixedName(this.prefixName(name));\r\n }\r\n\r\n private deletePrefixedName(prefixedName: string): void {\r\n const params = this.getCookieParams();\r\n this.cookieService.delete(\r\n prefixedName, // name: string,\r\n params.path, // path?: string,\r\n params.domain, // domain ?: string,\r\n params.secure, // secure ?: boolean,\r\n params.sameSite // sameSite ?: 'Lax' | 'None' | 'Strict'): void;\r\n );\r\n localStorage.removeItem(prefixedName);\r\n }\r\n\r\n public async set({\r\n name,\r\n value,\r\n serverSession,\r\n expiry,\r\n }: {\r\n name: string;\r\n value: any;\r\n serverSession: boolean;\r\n expiry?: Date;\r\n }): Promise<void> {\r\n const prefixedName = this.prefixName(name);\r\n\r\n let item: Item;\r\n\r\n if (serverSession) {\r\n item = {\r\n serverSession: true,\r\n data: await this.encryptionService.encryptToString(\r\n this.serverSessionEncryptionKey,\r\n value\r\n ),\r\n };\r\n } else {\r\n item = {\r\n data: value,\r\n };\r\n }\r\n\r\n if (expiry) {\r\n const key = await this.keyFactory.createKey();\r\n item.expiry = expiry.toISOString();\r\n item.data = await this.encryptionService.encryptToString(key, item.data);\r\n\r\n const cookieItem: CookieItem = {\r\n key: key.toJSON(true),\r\n };\r\n\r\n // If path is set to anything other than \"/\" then the cookie is only\r\n // accessible by JS if the current URL has the same prefix as the path.\r\n // Ideally we don't want the encryption key cookie to be sent at all, but\r\n // since the encrypted content is held in localstorage, it is not a security\r\n // risk, i.e. it is at least as secure as storing only in localstorage.\r\n const params = this.getCookieParams();\r\n this.cookieService.set(\r\n prefixedName, // name: string,\r\n JSON.stringify(cookieItem), // value: string,\r\n expiry, // expires?: number | Date,\r\n params.path, // path?: string,\r\n params.domain, // domain?: string,\r\n params.secure, // secure?: boolean,\r\n params.sameSite // sameSite?: 'Lax' | 'None' | 'Strict'\r\n );\r\n }\r\n\r\n localStorage.setItem(prefixedName, JSON.stringify(item));\r\n }\r\n\r\n public async get(name: string): Promise<any> {\r\n const prefixedName = this.prefixName(name);\r\n\r\n try {\r\n const ret = await this.getImpl(prefixedName);\r\n if (ret == null) {\r\n // Clear any cookies to keep things in sync.\r\n this.deletePrefixedName(prefixedName);\r\n }\r\n return ret;\r\n } catch (error) {\r\n this.deletePrefixedName(prefixedName);\r\n throw error;\r\n }\r\n }\r\n\r\n private async getImpl(name: string): Promise<any> {\r\n const itemString = localStorage.getItem(name);\r\n if (!itemString) {\r\n return null;\r\n }\r\n\r\n const item: Item = JSON.parse(itemString);\r\n\r\n let data: any;\r\n\r\n if (item.expiry) {\r\n const cookieItemString = this.cookieService.get(name);\r\n if (!cookieItemString) {\r\n // Probably expired, but we won't make any interpretations since if we only used\r\n // cookies we can't tell if it's expired or explicitly removed. So we just make\r\n // the behaviour here consistent with that.\r\n console.log('No cookie.');\r\n return null;\r\n }\r\n\r\n const cookieItem = JSON.parse(cookieItemString);\r\n\r\n const key = await KFS.asKey(cookieItem.key);\r\n\r\n data = await this.encryptionService.decrypt(key, item.data);\r\n } else {\r\n data = item.data;\r\n }\r\n\r\n if (item.serverSession) {\r\n data = await this.encryptionService.decrypt(\r\n this.serverSessionEncryptionKey,\r\n data\r\n );\r\n }\r\n\r\n return data;\r\n }\r\n}\r\n","import { Inject, Injectable } from '@angular/core';\r\nimport { Key, PassKey } from './cryptography.types';\r\nimport { LrNotFoundException } from '../_common/exceptions';\r\nimport { PersistService } from '../api/persist.service';\r\nimport { KeyFactoryService as KFS } from './key-factory.service';\r\nimport { LifeReadyConfig, LR_CONFIG } from '../life-ready.config';\r\n\r\nexport class UserKeys {\r\n passKey: PassKey;\r\n masterKey: Key;\r\n rootKey?: Key;\r\n pxk?: Key;\r\n sigPxk?: Key;\r\n}\r\n\r\ninterface StoredPassKey {\r\n id: string;\r\n jwk: object;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class KeyService {\r\n private readonly STORE_MASTER_KEY = 'masterKey';\r\n // variables\r\n private keys: UserKeys;\r\n private masterKey: Key;\r\n\r\n // AZ: This can't be change easily. It's basically a PassK or PassIdp rotation.\r\n // todo: we should eventually increase this periodically to match with Moore's law.\r\n // The iterations for each key are kept by the server as well but we assume the value\r\n // from the server is not trustworthy, so need to have minimum thresholds here.\r\n // If creating new keys, these minimum are used.\r\n public readonly MIN_PASS_IDP_PBKDF_ITER = 100000;\r\n public readonly MIN_PASS_KEY_PBKDF_ITER = 100000;\r\n public readonly MIN_LBOP_KEY_PBKDF_ITER = 100000;\r\n\r\n // These are used as the default values. They must be larger than the minimum values.\r\n public readonly DEFAULT_PASS_IDP_PBKDF_ITER = this.MIN_PASS_IDP_PBKDF_ITER;\r\n public readonly DEFAULT_PASS_KEY_PBKDF_ITER = this.MIN_PASS_KEY_PBKDF_ITER;\r\n public readonly DEFAULT_LBOP_KEY_PBKDF_ITER = this.MIN_LBOP_KEY_PBKDF_ITER;\r\n\r\n constructor(\r\n @Inject(LR_CONFIG) private config: LifeReadyConfig,\r\n private persistService: PersistService\r\n ) {\r\n this.resetKeys();\r\n }\r\n\r\n resetKeys() {\r\n this.keys = null;\r\n this.masterKey = null;\r\n }\r\n\r\n purgeKeys() {\r\n this.resetKeys();\r\n this.persistService.clear();\r\n }\r\n\r\n populateKeys(keys: UserKeys) {\r\n this.keys = keys;\r\n }\r\n\r\n public getCurrentPassKey(): Key {\r\n return this.keys.passKey;\r\n }\r\n\r\n public getCurrentMasterKey(): Key {\r\n return this.keys.masterKey;\r\n }\r\n\r\n public getCurrentRootKey(): Key {\r\n return this.keys.rootKey;\r\n }\r\n\r\n public getCurrentPxk(): Key {\r\n return this.keys.pxk;\r\n }\r\n\r\n public getCurrentSigPxk(): Key {\r\n return this.keys.sigPxk;\r\n }\r\n\r\n private expiresAfter(seconds: number): Date {\r\n return new Date(Date.now() + 1000 * seconds);\r\n }\r\n\r\n async persistMasterKey(\r\n masterKey: Key,\r\n expiresAfterSeconds: number\r\n ): Promise<void> {\r\n const storedKey = {\r\n id: masterKey.id,\r\n jwk: masterKey.jwk.toJSON(true),\r\n };\r\n\r\n this.masterKey = masterKey;\r\n\r\n // Save in an expirable cookie.\r\n await this.persistService.set({\r\n name: this.STORE_MASTER_KEY,\r\n value: storedKey,\r\n expiry: this.expiresAfter(expiresAfterSeconds),\r\n serverSession: !this.config.disableSessionEncryptionKey,\r\n });\r\n }\r\n\r\n async setMasterKeyExpiresAfterSeconds(seconds: number): Promise<void> {\r\n const storedKey = await this.persistService.get(this.STORE_MASTER_KEY);\r\n if (storedKey == null) {\r\n throw new LrNotFoundException(\r\n `Can not find masterKey in persisted storage using name: ${this.STORE_MASTER_KEY}`\r\n );\r\n }\r\n await this.persistService.set({\r\n name: this.STORE_MASTER_KEY,\r\n value: storedKey,\r\n expiry: this.expiresAfter(seconds),\r\n serverSession: !this.config.disableSessionEncryptionKey,\r\n });\r\n }\r\n\r\n // There's little benefit in using WebCrypto's none-extractable keys because if there\r\n // is an XSS attack, then the attacker has control over the js that downloads the keys. The\r\n // attacker can modify the code to import the keys as extractable. So none-extractable keys\r\n // are only useful if they are already persisted and the user cannot download any more keys,\r\n // which is not feasible.\r\n // So storing the PassKey in localstorage for now, at least till we know what the usage\r\n // pattern is, i.e. how often do we need to use the RootK, MaterK, and PassK.\r\n async loadMasterKey(masterKeyId: string): Promise<Key> {\r\n if (!this.masterKey) {\r\n const storedKey = await this.persistService.get(this.STORE_MASTER_KEY);\r\n\r\n if (!storedKey) {\r\n throw new LrNotFoundException(\r\n 'Could not find masterKey in persisted storage'\r\n );\r\n }\r\n\r\n if (storedKey.id !== masterKeyId) {\r\n throw new LrNotFoundException(\r\n `masterKeyId ${storedKey.id} in persisted storage does not match the one requested ${masterKeyId}`\r\n );\r\n }\r\n\r\n storedKey.jwk = await KFS.asKey(storedKey.jwk);\r\n\r\n this.masterKey = storedKey;\r\n }\r\n\r\n return this.masterKey;\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport graphlib, { Graph } from '@dagrejs/graphlib';\r\nimport _ from 'lodash';\r\nimport { JWK } from 'node-jose';\r\nimport { CurrentUserKey } from '../users/profile.types';\r\nimport {\r\n LrException,\r\n LrEncryptionException,\r\n LrNotFoundException,\r\n LrBadArgumentException,\r\n} from '../_common/exceptions';\r\nimport {\r\n Edge,\r\n EdgeType,\r\n Key,\r\n KeyGraphResponse,\r\n Node,\r\n NodeType,\r\n PassKey,\r\n} from './cryptography.types';\r\nimport {\r\n asJwk,\r\n DecryptOptions,\r\n EncryptionService,\r\n isSymmetricKey,\r\n} from './encryption.service';\r\nimport {\r\n KeyFactoryService,\r\n KeyFactoryService as KFS,\r\n} from './key-factory.service';\r\nimport { KeyService } from './key.service';\r\n\r\nexport interface GraphKey extends Key {\r\n task?: Promise<any>;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class KeyGraphService {\r\n private graph: Graph;\r\n // private keyCache: {\r\n // [id: string]: Key;\r\n // };\r\n\r\n constructor(\r\n private encryptionService: EncryptionService,\r\n private keyService: KeyService\r\n ) {\r\n this.purgeKeys();\r\n }\r\n\r\n purgeKeys() {\r\n this.graph = new Graph();\r\n // this.keyCache = null;\r\n }\r\n\r\n async populateKeys(userKey: CurrentUserKey) {\r\n this.keyService.populateKeys({\r\n passKey: userKey.passKey,\r\n masterKey: await this.keyService.loadMasterKey(userKey.masterKey.id),\r\n rootKey: await this.unwrapKey(userKey.masterKey.id, userKey.rootKey.id),\r\n pxk: await this.unwrapKey(userKey.masterKey.id, userKey.pxk.id),\r\n sigPxk: await this.unwrapKey(userKey.masterKey.id, userKey.sigPxk.id),\r\n });\r\n }\r\n\r\n hasKey(keyId: string) {\r\n return !!this.graph.node(keyId);\r\n }\r\n\r\n private getNode(id, type): GraphKey | PassKey {\r\n const node = this.graph.node(id);\r\n if (!node) {\r\n throw new LrNotFoundException(\r\n `Key graphs does not contain key id: ${id}`\r\n );\r\n }\r\n if (node.type !== type) {\r\n throw new LrException({\r\n message: `Key with id ${id} is not of type ${type}`,\r\n });\r\n }\r\n return node.data;\r\n }\r\n\r\n key(id): GraphKey {\r\n return this.getNode(id, NodeType.Key);\r\n }\r\n\r\n passKey(id): PassKey {\r\n return this.getNode(id, NodeType.PassKey);\r\n }\r\n\r\n addKeys(src: KeyGraphResponse) {\r\n // Keys\r\n if (src.keys) {\r\n // What key graph returns can not be customized. So keys are essentially immutable.\r\n // Therefore, if a key exists, there's no reason to update it.\r\n for (const key of src.keys) {\r\n // Note using Relay global id allows us to not worry about clashing node id\r\n if (this.graph.hasNode(key.id)) {\r\n continue;\r\n }\r\n\r\n const node: Node = {\r\n type: NodeType.Key,\r\n data: _.cloneDeep(key),\r\n };\r\n\r\n this.graph.setNode(key.id, node);\r\n }\r\n }\r\n\r\n // KeyLinks\r\n if (src.keyLinks) {\r\n for (const keyLink of src.keyLinks) {\r\n if (this.graph.hasEdge(keyLink.wrappingKeyId, keyLink.keyId)) {\r\n continue;\r\n }\r\n\r\n const edge: Edge = {\r\n type: EdgeType.KeyLink,\r\n data: _.cloneDeep(keyLink),\r\n };\r\n // Edge goes from wrapping key to wrapped key.\r\n this.graph.setEdge(keyLink.wrappingKeyId, keyLink.keyId, edge);\r\n }\r\n }\r\n\r\n // PassKeyLinks\r\n if (src.passKeyLinks) {\r\n for (const passKeyLink of src.passKeyLinks) {\r\n if (this.graph.hasEdge(passKeyLink.passKeyId, passKeyLink.keyId)) {\r\n continue;\r\n }\r\n\r\n const edge: Edge = {\r\n type: EdgeType.PassKeyLink,\r\n data: _.cloneDeep(passKeyLink),\r\n };\r\n // Edge goes from wrapping key to wrapped key.\r\n this.graph.setEdge(passKeyLink.passKeyId, passKeyLink.keyId, edge);\r\n }\r\n }\r\n\r\n // The graph is the single source of truth. These are lazily calculated.\r\n // this.keyCache = null;\r\n }\r\n\r\n tracePath(distances, keyId: string): Edge[] {\r\n // The node label is the same as the id of the key nodes.\r\n const ret: Edge[] = [];\r\n let node = keyId;\r\n if (!distances[node].predecessor) {\r\n return null;\r\n }\r\n\r\n while (distances[node].predecessor) {\r\n const child = distances[node].predecessor;\r\n ret.push(this.graph.edge(child, node));\r\n node = child;\r\n }\r\n\r\n // After reverse, the first element is the passkey\r\n ret.reverse();\r\n\r\n return ret;\r\n }\r\n\r\n getPath(knownKeyId: string, keyId: string): Edge[] {\r\n if (!knownKeyId || typeof knownKeyId !== 'string') {\r\n throw new LrEncryptionException(\r\n `Param knownKeyId wrong format: ${knownKeyId}`\r\n );\r\n }\r\n if (!keyId || typeof keyId !== 'string') {\r\n throw new LrEncryptionException(`Param keyId wrong format: ${keyId}`);\r\n }\r\n\r\n // => { A: { distance: 0 },\r\n // B: { distance: 6, predecessor: 'C' },\r\n // C: { distance: 4, predecessor: 'A' },\r\n // D: { distance: 2, predecessor: 'A' },\r\n // E: { distance: 8, predecessor: 'F' },\r\n // F: { distance: 4, predecessor: 'D' } }\r\n const distances = graphlib.alg.dijkstra(this.graph, knownKeyId);\r\n\r\n // Trace path from keyId to knownKeyId\r\n return this.tracePath(distances, keyId);\r\n }\r\n\r\n async getJwkKey(\r\n keyOrId: string | Key,\r\n getKeyIdCallback?: () => Promise<string> | string\r\n ): Promise<JWK.Key> {\r\n return (await this.getKey(keyOrId, getKeyIdCallback)).jwk;\r\n }\r\n\r\n // We assume that when a keyId is fetched, the key graph\r\n // for the key is also returned and merged into the client-side\r\n // key graph. By insisting a keyId is returned instead of the\r\n // actual key we ensure key-graph is consistent.\r\n async getKey(\r\n keyOrId: string | Key,\r\n getKeyIdCallback?: () => Promise<string> | string\r\n ): Promise<Key> {\r\n let keyId = typeof keyOrId === 'string' ? keyOrId : keyOrId?.id;\r\n\r\n if (!this.hasKey(keyId) && getKeyIdCallback) {\r\n keyId = await getKeyIdCallback();\r\n }\r\n // else, continue and let it fail.\r\n\r\n const key = this.key(keyId);\r\n if (key.jwk) {\r\n return key;\r\n } else {\r\n return this.unwrapKey(this.keyService.getCurrentMasterKey().id, keyId);\r\n }\r\n }\r\n\r\n private async _unwrapLink(wrappingKey, link, dstKey) {\r\n // console.log(\"_unwrapLink:\", link.data.keyId);\r\n const wrappedKey = JSON.parse(link.data.wrappedKey);\r\n // Signatures of keys contain the key itself. This way we only need\r\n // to access the KeyLinks to decrypt/verify keys.\r\n let nextRawKey;\r\n if (wrappedKey.signatures) {\r\n nextRawKey = await this.encryptionService.verify(wrappingKey, wrappedKey);\r\n } else {\r\n nextRawKey = await this.encryptionService.decrypt(\r\n wrappingKey,\r\n wrappedKey\r\n );\r\n }\r\n dstKey.jwk = await KFS.asKey(nextRawKey);\r\n dstKey.task = null;\r\n }\r\n\r\n private async _unwrap(key: JWK.Key, path: Edge[]): Promise<JWK.Key> {\r\n for (const link of path) {\r\n const dstKey = this.key(link.data.keyId);\r\n // console.log(\"key: \", link.data.keyId);\r\n if (dstKey.jwk) {\r\n key = dstKey.jwk;\r\n // console.log(\"Returning cached key: \", link.data.keyId);\r\n continue;\r\n }\r\n\r\n if (!dstKey.task) {\r\n dstKey.task = this._unwrapLink(key, link, dstKey);\r\n }\r\n\r\n await dstKey.task;\r\n key = dstKey.jwk;\r\n }\r\n\r\n return key;\r\n }\r\n\r\n public async unwrapWithPassKey(\r\n passKeyId: string,\r\n passKey: JWK.Key,\r\n keyId: string\r\n ): Promise<Key> {\r\n // Get path of the directory key.\r\n const path = this.getPath(passKeyId, keyId);\r\n\r\n return {\r\n id: keyId,\r\n jwk: await this._unwrap(passKey, path),\r\n };\r\n }\r\n\r\n async unwrapKey(masterKeyId: string, keyId: string): Promise<Key> {\r\n // The first key should be a masterKey\r\n const masterKey = await this.keyService.loadMasterKey(masterKeyId);\r\n\r\n if (masterKeyId === keyId) {\r\n return masterKey;\r\n }\r\n\r\n // Get path of the directory key.\r\n const path = this.getPath(masterKey.id, keyId);\r\n\r\n return {\r\n id: keyId,\r\n jwk: await this._unwrap(masterKey.jwk, path),\r\n };\r\n }\r\n\r\n async decryptFromString<T>(\r\n keyOrId: string | Key,\r\n cipherData: string,\r\n options?: DecryptOptions\r\n ): Promise<T> {\r\n if (cipherData) {\r\n const key = await this.getJwkKey(keyOrId);\r\n return (await this.encryptionService.decrypt(\r\n key,\r\n JSON.parse(cipherData),\r\n options\r\n )) as any;\r\n }\r\n return null;\r\n }\r\n\r\n async decryptFile(keyId: string, file: any): Promise<any> {\r\n const key = await this.getJwkKey(keyId);\r\n return (await this.encryptionService.decrypt(key, file, {\r\n payloadType: 'ArrayBuffer',\r\n })) as any;\r\n }\r\n\r\n // TODO rename this to encrypt() and use as the most common usecase\r\n async encryptToString(\r\n key: string | Key | JWK.Key,\r\n content: any\r\n ): Promise<string> {\r\n // Empty string should be encrypted since you want to clear the field.\r\n // Null is not encrypted because it's not valid JSON in the old JSON spec. Use\r\n // empty string instead. It'll function as a logic false as well.\r\n // Note that passing in empty string means it'll be encrypted which verifies\r\n // it's integrity. But we still want to have a way to set the DB field\r\n // to NULL, so we explicitly return null when content == null. A null\r\n // variable in graphql mutation on KC server clears the field to NULL.\r\n if (content == null) {\r\n return null;\r\n }\r\n\r\n const jwk = asJwk(key) || (await this.getJwkKey(key as string | Key));\r\n return this.encryptionService.encryptToString(jwk, content);\r\n }\r\n\r\n // Wraps a symmetric encryption key.\r\n // Throws exception if wrapping public keys.\r\n async wrapKey<T>(\r\n wrappingKey: string | Key | JWK.Key,\r\n key: JWK.Key\r\n ): Promise<string> {\r\n if (!isSymmetricKey(key)) {\r\n throw new LrBadArgumentException(\r\n 'Only allowing wrapping of symmetric keys.'\r\n );\r\n }\r\n\r\n return this.encryptToString(wrappingKey, key.toJSON(true));\r\n }\r\n\r\n // TODO\r\n // async wrapPublicKey<T>();\r\n // async wrapPrivateKey<T>();\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport { Apollo } from 'apollo-angular';\r\nimport { QueryOptions, MutationOptions } from '@apollo/client/core';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { HasKeyGraph } from '../cryptography/cryptography.types';\r\nimport { handleApolloError } from '../_common/exceptions';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class LrApolloService {\r\n constructor(private apollo: Apollo, private keyGraph: KeyGraphService) {}\r\n\r\n private addKeys(response) {\r\n if ((response.data as HasKeyGraph).keyGraph) {\r\n this.keyGraph.addKeys((response.data as HasKeyGraph).keyGraph);\r\n }\r\n }\r\n\r\n async query<T, V = { [key: string]: any }>(\r\n options: QueryOptions<V>\r\n ): Promise<T> {\r\n const response = await this.apollo.query<T, V>(options).toPromise();\r\n\r\n handleApolloError(response.errors);\r\n\r\n this.addKeys(response);\r\n\r\n return response.data;\r\n }\r\n\r\n async mutate<T extends any, V = { [key: string]: any }>(\r\n options: MutationOptions<T, V>\r\n ): Promise<T> {\r\n const response = await this.apollo.mutate<T>(options).toPromise();\r\n\r\n handleApolloError(response.errors);\r\n\r\n this.addKeys(response);\r\n\r\n return response.data;\r\n }\r\n}\r\n","import gql from 'graphql-tag';\r\n\r\nconst KeyGraphFragmentBase = `\r\n{\r\n keys {\r\n id\r\n }\r\n keyLinks {\r\n keyId\r\n wrappingKeyId\r\n wrappedKey\r\n }\r\n passKeys {\r\n id\r\n }\r\n passKeyLinks {\r\n keyId\r\n passKeyId\r\n wrappedKey\r\n }\r\n __typename\r\n}\r\n`;\r\n\r\nexport const KeyGraphFragment = gql`\r\nfragment KeyGraphFragment on KeyGraphType ${KeyGraphFragmentBase}\r\n`;\r\n\r\nexport const KeyGraphField = `keyGraph ${KeyGraphFragmentBase}`;\r\n\r\nexport const FetchKeyGraphField = `keyGraph: fetchKeyGraph ${KeyGraphFragmentBase}`;\r\n\r\nexport const FileQuery = gql`\r\n query File($id: LrRelayIdInput!, $cachedKeyIds: [LrRelayIdInput!]) {\r\n file(id: $id) {\r\n id\r\n keyId\r\n currentVersion {\r\n id\r\n operation\r\n state {\r\n keyId\r\n plainMeta\r\n cipherMeta\r\n contentResource\r\n }\r\n }\r\n versions {\r\n edges {\r\n node {\r\n id\r\n state {\r\n keyId\r\n plainMeta\r\n cipherMeta\r\n contentResource\r\n }\r\n }\r\n }\r\n }\r\n parentDirectoryLinks {\r\n edges {\r\n node {\r\n parentDirectory {\r\n id\r\n plainMeta\r\n }\r\n }\r\n }\r\n }\r\n }\r\n keyGraph(cachedKeyIds: $cachedKeyIds) {\r\n ...KeyGraphFragment\r\n }\r\n }\r\n ${KeyGraphFragment}\r\n`;\r\n\r\nexport const DirectoryQuery = gql`\r\n query Directory($id: LrRelayIdInput!, $cachedKeyIds: [LrRelayIdInput!]) {\r\n directory(id: $id) {\r\n id\r\n keyId\r\n plainMeta\r\n cipherMeta\r\n }\r\n keyGraph(cachedKeyIds: $cachedKeyIds) {\r\n ...KeyGraphFragment\r\n }\r\n }\r\n ${KeyGraphFragment}\r\n`;\r\n\r\nexport const CreateFileQuery = gql`\r\n mutation CreateFile($input: CreateFileInput!) {\r\n createFile(input: $input) {\r\n file {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UpdateFileQuery = gql`\r\n mutation UpdateFile($input: UpdateFileInput!) {\r\n updateFile(input: $input) {\r\n file {\r\n id\r\n currentVersion {\r\n id\r\n state {\r\n id\r\n }\r\n }\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const RevertFileQuery = gql`\r\n mutation RevertFile($input: RevertFileInput!) {\r\n revertFile(input: $input) {\r\n file {\r\n id\r\n currentVersion {\r\n id\r\n state {\r\n id\r\n }\r\n }\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const MoveFileQuery = gql`\r\n mutation MoveFile(\r\n $fileId: LrRelayIdInput!\r\n $fromParentDirectoryId: LrRelayIdInput!\r\n $toParentDirectoryId: LrRelayIdInput!\r\n $wrappingKeyId: LrRelayIdInput!\r\n $wrappedKey: String!\r\n ) {\r\n moveFile(\r\n input: {\r\n fileId: $fileId\r\n fromParentDirectoryId: $fromParentDirectoryId\r\n toParentDirectoryId: $toParentDirectoryId\r\n wrappingKeyId: $wrappingKeyId\r\n wrappedKey: $wrappedKey\r\n }\r\n ) {\r\n file {\r\n id\r\n parentDirectoryLinks {\r\n edges {\r\n node {\r\n parentDirectory {\r\n plainMeta\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const MoveDirectoryQuery = gql`\r\n mutation MoveDirectory(\r\n $directoryId: LrRelayIdInput!\r\n $fromParentDirectoryId: LrRelayIdInput\r\n $toParentDirectoryId: LrRelayIdInput!\r\n $wrappedKey: String!\r\n $wrappingKeyId: LrRelayIdInput!\r\n ) {\r\n moveDirectory(\r\n input: {\r\n directoryId: $directoryId\r\n fromParentDirectoryId: $fromParentDirectoryId\r\n toParentDirectoryId: $toParentDirectoryId\r\n wrappedKey: $wrappedKey\r\n wrappingKeyId: $wrappingKeyId\r\n }\r\n ) {\r\n directory {\r\n id\r\n parentDirectoryLinks {\r\n edges {\r\n node {\r\n parentDirectory {\r\n plainMeta\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n`;\r\n","import { HasEdges } from './../_common/types';\r\nimport { HasKeyGraph, PassKey } from './../cryptography/cryptography.types';\r\nimport { ApiCurrentUser, ApiContactCard } from './profile.types';\r\nimport gql from 'graphql-tag';\r\nimport { KeyGraphFragment } from '../_common/queries.gql';\r\n\r\nexport interface CurrentUserQueryType extends HasKeyGraph {\r\n currentUser: ApiCurrentUser;\r\n contactCards: HasEdges<ApiContactCard>;\r\n userPlans: any[];\r\n}\r\n\r\nexport const CurrentUserQuery = gql`\r\n query {\r\n currentUser {\r\n id\r\n username\r\n currentUserKey {\r\n passKey {\r\n id\r\n passKeyParams\r\n passIdpParams\r\n wrappedPassIdpVerifierPrk\r\n created\r\n }\r\n masterKey {\r\n id\r\n }\r\n rootKey {\r\n id\r\n }\r\n pxk {\r\n id\r\n }\r\n sigPxk {\r\n id\r\n }\r\n }\r\n userDelete {\r\n id\r\n created\r\n state\r\n }\r\n features {\r\n myVault\r\n tpVault\r\n shareVault\r\n }\r\n sessionEncryptionKey\r\n }\r\n userPlans {\r\n id\r\n stripe {\r\n subscriptionId\r\n }\r\n plan {\r\n name\r\n data\r\n state\r\n }\r\n periodEnd\r\n }\r\n contactCards(orderBy: \"created\") {\r\n edges {\r\n node {\r\n id\r\n key {\r\n id\r\n }\r\n cipherData\r\n plainData\r\n }\r\n }\r\n }\r\n keyGraph {\r\n ...KeyGraphFragment\r\n }\r\n }\r\n ${KeyGraphFragment}\r\n`;\r\n\r\nexport const CreateContactCardMutation = gql`\r\n mutation CreateContactCardMutation($input: CreateContactCardInput!) {\r\n createContactCard(input: $input) {\r\n contactCard {\r\n id\r\n key {\r\n id\r\n }\r\n cipherData\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UpdateContactCardMutation = gql`\r\n mutation UpdateContactCardMutation($input: UpdateContactCardInput!) {\r\n updateContactCard(input: $input) {\r\n contactCard {\r\n id\r\n key {\r\n id\r\n }\r\n cipherData\r\n }\r\n }\r\n }\r\n`;\r\n","import { ContactCard } from '../api/contact-card.service';\r\nimport { PassIdpParams, PassKey } from '../cryptography/cryptography.types';\r\nimport { UserDelete } from './user.types';\r\n\r\nexport class CurrentUserKey {\r\n passKey?: PassKey;\r\n masterKey?: { id: string };\r\n rootKey?: { id: string };\r\n pxk?: { id: string };\r\n sigPxk?: { id: string };\r\n}\r\n\r\nexport class ApiCurrentUser {\r\n id: string;\r\n username: string;\r\n currentUserKey: CurrentUserKey;\r\n userDelete: UserDelete;\r\n features: any;\r\n sessionEncryptionKey: string;\r\n}\r\n\r\nexport class ApiContactCard {\r\n id: string;\r\n cipherData: string;\r\n key: {\r\n id: string;\r\n };\r\n}\r\n\r\nexport class ContactCardName {\r\n name: string;\r\n title?: string;\r\n firstName?: string;\r\n lastName?: string;\r\n\r\n constructor(input: any) {\r\n this.name = input.name;\r\n this.title = input.title;\r\n this.firstName = input.firstName;\r\n this.lastName = input.lastName;\r\n }\r\n}\r\n\r\nexport class ContactCardAddress {\r\n fullAddress: string;\r\n streetAddress: string;\r\n suburb: string;\r\n state: string;\r\n postcode: string;\r\n country: string;\r\n}\r\n\r\nexport class MainContactCardProperty<T> {\r\n value: T;\r\n hasMultiple: boolean;\r\n\r\n values?: { id: string; label: string; value: T }[];\r\n}\r\n\r\nexport class MainContactCardFields {\r\n name: MainContactCardProperty<ContactCardName>;\r\n email: MainContactCardProperty<string>;\r\n image: MainContactCardProperty<string>;\r\n phone: MainContactCardProperty<string>;\r\n address: MainContactCardProperty<ContactCardAddress>;\r\n}\r\n\r\nexport class MainContactCard extends MainContactCardFields {\r\n id: string;\r\n keyId: string;\r\n}\r\n\r\nexport class MainContactCardPlainFields {\r\n name: ContactCardName;\r\n}\r\n\r\nexport enum PasswordChangeStatus {\r\n InProgress = 'IN_PROGRESS',\r\n Recovery = 'RECOVERY',\r\n}\r\n\r\nexport class PassIdpApiResult {\r\n passwordChangeStatus?: PasswordChangeStatus;\r\n currentPassIdpParams: PassIdpParams;\r\n newPassIdpParams: PassIdpParams;\r\n tpPasswordReset: {\r\n passIdpParams: PassIdpParams;\r\n resetUsername: string;\r\n };\r\n}\r\n\r\nexport class TrustedPartyDetails {\r\n name: ContactCardName;\r\n email?: string;\r\n image?: string;\r\n phones?: { label: string; value: string }[];\r\n addresses?: {\r\n label: string;\r\n value: ContactCardAddress;\r\n }[];\r\n}\r\n","import { HasKeyGraph } from './../cryptography/cryptography.types';\r\nimport { KeyGraphFragment } from '../_common/queries.gql';\r\nimport gql from 'graphql-tag';\r\nimport { HasKeyGraphEdges, HasEdges } from '../_common/types';\r\n\r\nexport const DEFAULT_BREADCRUMB_DEPTH = 5;\r\nexport const DEFAULT_DESCENDANTS_DEPTH = 5;\r\n\r\nexport enum DirectoryType {\r\n Vault = 'vault',\r\n Category = 'category',\r\n Record = 'record',\r\n}\r\n\r\nexport const DefaultVaultFilter = JSON.stringify({\r\n filter: [\r\n {\r\n contains: {\r\n directoryType: DirectoryType.Vault,\r\n default: true,\r\n },\r\n },\r\n ],\r\n});\r\n\r\nexport const CategoryFilter = JSON.stringify({\r\n filter: [\r\n {\r\n contains: {\r\n directoryType: DirectoryType.Category,\r\n },\r\n },\r\n ],\r\n});\r\n\r\nexport const RecordFilter = JSON.stringify({\r\n filter: [\r\n {\r\n contains: {\r\n directoryType: DirectoryType.Record,\r\n },\r\n },\r\n ],\r\n});\r\n\r\nexport const AccessFields = `\r\naccessRoles {\r\n role\r\n method\r\n inheritedFrom {\r\n id\r\n }\r\n trustedParty {\r\n id\r\n }\r\n isIssuer\r\n}`;\r\n\r\nconst descendantDirectories = `\r\ndescendantDirectories(depth: ${DEFAULT_DESCENDANTS_DEPTH}, plainMeta: $categoryFilter, archived: false) {\r\n recordsCount: directoriesCount(plainMeta: $recordFilter, archived: false)\r\n}\r\n`;\r\n\r\nexport const CategoryFields = `\r\n id\r\n keyId\r\n archived\r\n plainMeta\r\n cipherMeta\r\n ${AccessFields}\r\n ${descendantDirectories}\r\n`;\r\n\r\nexport const VaultFields = `\r\n id\r\n keyId\r\n plainMeta\r\n cipherMeta\r\n`;\r\n\r\nexport const GetRootDirectoryIdsQuery = gql`\r\n query GetRootDirectoryIdsQuery($archived: Boolean) {\r\n rootDirectories(archived: $archived) {\r\n edges {\r\n node {\r\n id\r\n }\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const GetCategoriesQuery = gql`\r\nquery GetCategories($vaultFilter: LrJSONFilter!, $categoryFilter: LrJSONFilter!, $recordFilter: LrJSONFilter!, $archived: Boolean, $cachedKeyIds: [LrRelayIdInput!])\r\n{\r\n vaults: rootDirectories(plainMeta: $vaultFilter) {\r\n edges {\r\n node {\r\n childDirectoryLinks(plainMeta: $categoryFilter, orderBy: \"created\", archived: $archived) {\r\n edges {\r\n node {\r\n childDirectory {\r\n ${CategoryFields}\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n keyGraph(cachedKeyIds: $cachedKeyIds) {\r\n ...KeyGraphFragment\r\n }\r\n}\r\n${KeyGraphFragment}\r\n`;\r\n\r\nexport const GetVaultsQuery = gql`\r\nquery GetVaults($plainMetaFilter: LrJSONFilter!, $cachedKeyIds: [LrRelayIdInput!])\r\n{\r\n list: rootDirectories(plainMeta: $plainMetaFilter, orderBy: \"created\") {\r\n edges {\r\n node {\r\n ${VaultFields}\r\n }\r\n }\r\n }\r\n keyGraph(cachedKeyIds: $cachedKeyIds) {\r\n ...KeyGraphFragment\r\n }\r\n}\r\n${KeyGraphFragment}\r\n`;\r\n\r\nexport interface GetTrustedPartyCategoriesQueryType extends HasKeyGraph {\r\n tp: {\r\n sharedItems: {\r\n list: HasEdges<any>;\r\n records: HasEdges<any>;\r\n };\r\n };\r\n}\r\n\r\nexport const GetTrustedPartyCategoriesQuery = gql`\r\nquery GetTrustedPartyCategoriesQuery($trustedPartyId: LrRelayIdInput!, $categoryFilter: LrJSONFilter!, $recordFilter: LrJSONFilter!, $contentFilter: LrJSONFilter, $cachedKeyIds: [LrRelayIdInput!])\r\n{\r\n tp(id: $trustedPartyId) {\r\n sharedItems {\r\n list: directories(plainMeta: $categoryFilter, orderBy: \"created\") {\r\n edges {\r\n node {\r\n ${CategoryFields}\r\n }\r\n }\r\n }\r\n records: directories(plainMeta: $recordFilter, orderBy: \"created\") {\r\n edges {\r\n node {\r\n id\r\n keyId\r\n archived\r\n plainMeta\r\n cipherMeta\r\n created\r\n modified\r\n ${AccessFields}\r\n content: childFileLinks(plainMeta: $contentFilter) {\r\n edges {\r\n node {\r\n childFile {\r\n id\r\n archived\r\n currentVersion {\r\n state {\r\n keyId\r\n plainMeta\r\n cipherMeta\r\n created\r\n modified\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n keyGraph(cachedKeyIds: $cachedKeyIds) {\r\n ...KeyGraphFragment\r\n }\r\n}\r\n${KeyGraphFragment}\r\n`;\r\n\r\nexport interface GetMySharedCategoriesQueryType extends HasKeyGraph {\r\n tp: {\r\n myItems: {\r\n list: HasEdges<any>;\r\n records: HasEdges<any>;\r\n };\r\n };\r\n}\r\n\r\nexport const GetMySharedCategoriesQuery = gql`\r\nquery GetMySharedCategoriesQuery($trustedPartyId: LrRelayIdInput!, $categoryFilter: LrJSONFilter!, $recordFilter: LrJSONFilter!, $contentFilter: LrJSONFilter, $cachedKeyIds: [LrRelayIdInput!])\r\n{\r\n tp(id: $trustedPartyId) {\r\n myItems {\r\n list: directories(plainMeta: $categoryFilter, orderBy: \"created\") {\r\n edges {\r\n node {\r\n ${CategoryFields}\r\n }\r\n }\r\n }\r\n records: directories(plainMeta: $recordFilter, orderBy: \"created\") {\r\n edges {\r\n node {\r\n id\r\n keyId\r\n archived\r\n plainMeta\r\n cipherMeta\r\n created\r\n modified\r\n ${AccessFields}\r\n content: childFileLinks(plainMeta: $contentFilter) {\r\n edges {\r\n node {\r\n childFile {\r\n id\r\n archived\r\n currentVersion {\r\n state {\r\n keyId\r\n plainMeta\r\n cipherMeta\r\n created\r\n modified\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n keyGraph(cachedKeyIds: $cachedKeyIds) {\r\n ...KeyGraphFragment\r\n }\r\n}\r\n${KeyGraphFragment}\r\n`;\r\n\r\nexport const parentCategoriesField = (depth = DEFAULT_BREADCRUMB_DEPTH) => {\r\n if (!depth) {\r\n return '';\r\n }\r\n return `\r\nparentCategories: parentDirectoryLinks(plainMeta: $categoryFilter) {\r\n edges {\r\n node {\r\n parentDirectory {\r\n id\r\n keyId\r\n archived\r\n plainMeta\r\n cipherMeta\r\n ${parentCategoriesField(depth - 1)}\r\n ${AccessFields}\r\n }\r\n }\r\n }\r\n}\r\n`;\r\n};\r\n\r\nexport const GetCategoryQuery = (\r\n depth: number = DEFAULT_BREADCRUMB_DEPTH\r\n) => gql`\r\nquery GetCategory(\r\n $id: LrRelayIdInput!,\r\n $categoryFilter: LrJSONFilter!,\r\n $recordFilter: LrJSONFilter!,\r\n $contentFilter: LrJSONFilter,\r\n $cachedKeyIds: [LrRelayIdInput!]) {\r\n category: directory(id: $id) {\r\n id\r\n keyId\r\n archived\r\n plainMeta\r\n cipherMeta\r\n ${AccessFields}\r\n ${descendantDirectories}\r\n ${parentCategoriesField(depth)}\r\n subCategories: childDirectoryLinks(plainMeta: $categoryFilter, orderBy: \"created\") {\r\n edges {\r\n node {\r\n childDirectory {\r\n ${CategoryFields}\r\n }\r\n }\r\n }\r\n }\r\n records: childDirectoryLinks(plainMeta: $recordFilter, orderBy: \"created\") {\r\n edges {\r\n node {\r\n childDirectory {\r\n id\r\n keyId\r\n archived\r\n plainMeta\r\n cipherMeta\r\n created\r\n modified\r\n ${AccessFields}\r\n content: childFileLinks(plainMeta: $contentFilter) {\r\n edges {\r\n node {\r\n childFile {\r\n id\r\n archived\r\n currentVersion {\r\n state {\r\n keyId\r\n plainMeta\r\n cipherMeta\r\n created\r\n modified\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n keyGraph(cachedKeyIds: $cachedKeyIds) {\r\n ...KeyGraphFragment\r\n }\r\n}\r\n${KeyGraphFragment} `;\r\n\r\nexport const GetCategoryKeyIdQuery = gql`\r\n query GetCategoryKeyIdQuery(\r\n $id: LrRelayIdInput!\r\n $cachedKeyIds: [LrRelayIdInput!]\r\n ) {\r\n category: directory(id: $id) {\r\n keyId\r\n }\r\n keyGraph(cachedKeyIds: $cachedKeyIds) {\r\n ...KeyGraphFragment\r\n }\r\n }\r\n ${KeyGraphFragment}\r\n`;\r\n\r\nexport const CreateCategoryMutation = gql`\r\n mutation CreateCategory(\r\n $plainMeta: LrJSONString\r\n $cipherMeta: String\r\n $parentDirectories: [ParentDirectoryInput!]\r\n $parentRootDirectory: ParentRootDirectoryInput\r\n ) {\r\n new: createDirectory(\r\n input: {\r\n plainMeta: $plainMeta\r\n cipherMeta: $cipherMeta\r\n parentDirectories: $parentDirectories\r\n parentRootDirectory: $parentRootDirectory\r\n }\r\n ) {\r\n category: directory {\r\n id\r\n keyId\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const CreateVaultMutation = gql`\r\n mutation CreateCategory(\r\n $plainMeta: LrJSONString\r\n $cipherMeta: String\r\n $parentRootDirectory: ParentRootDirectoryInput\r\n ) {\r\n new: createDirectory(\r\n input: {\r\n plainMeta: $plainMeta\r\n cipherMeta: $cipherMeta\r\n parentRootDirectory: $parentRootDirectory\r\n }\r\n ) {\r\n vault: directory {\r\n id\r\n keyId\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UpdateCategoryMutation = gql`\r\n mutation UpdateCategory($input: UpdateDirectoryInput!) {\r\n updateDirectory(input: $input) {\r\n directory {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const DeleteCategoryMutation = gql`\r\n mutation DeleteCategory($categoryId: LrRelayIdInput!) {\r\n deleteDirectory(input: { directoryId: $categoryId }) {\r\n id\r\n }\r\n }\r\n`;\r\n\r\nexport const ArchiveDirectoryMutation = gql`\r\n mutation ArchiveDirectory($input: ArchiveDirectoryInput!) {\r\n archiveDirectory(input: $input) {\r\n directory {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UnarchiveDirectoryMutation = gql`\r\n mutation UnarchiveDirectory($input: UnarchiveDirectoryInput!) {\r\n unarchiveDirectory(input: $input) {\r\n directory {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n","import { Injectable } from '@angular/core';\r\nimport { JWK } from 'node-jose';\r\nimport { LrApolloService } from '../api/lr-apollo.service';\r\nimport { GetCategoryKeyIdQuery } from '../category/category.gql';\r\nimport { LrBadArgumentException } from '../_common/exceptions';\r\nimport { Key, PayloadType } from './cryptography.types';\r\nimport {\r\n asJwk,\r\n DecryptOptions,\r\n EncryptionService,\r\n isSymmetricKey,\r\n} from './encryption.service';\r\nimport { KeyFactoryService } from './key-factory.service';\r\nimport { KeyGraphService } from './key-graph.service';\r\nimport { KeyService } from './key.service';\r\n\r\nexport interface HasCipherMeta {\r\n keyId: string;\r\n cipherMeta: string;\r\n}\r\n\r\nexport class WrappedContent {\r\n key: JWK.Key;\r\n cipherMeta: string;\r\n wrappedKeys?: WrappingKey[];\r\n rootKey?: WrappingKey;\r\n}\r\n\r\nexport class WrappingKey {\r\n directoryId?: string;\r\n wrappingKeyId: string;\r\n wrappedKey: string;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class KeyMetaService {\r\n constructor(\r\n private encryptionService: EncryptionService,\r\n private keyGraph: KeyGraphService,\r\n private lrApollo: LrApolloService,\r\n private keyService: KeyService,\r\n private keyFactory: KeyFactoryService\r\n ) {}\r\n\r\n // async decryptFromString<T>(\r\n // keyOrId: string | Key,\r\n // cipherData: string,\r\n // options?: DecryptOptions\r\n // ): Promise<T> {\r\n // if (cipherData) {\r\n // const key = await this.keyGraphService.getJwkKey(keyOrId);\r\n // return (await this.encryptionService.decrypt(\r\n // key,\r\n // JSON.parse(cipherData),\r\n // options\r\n // )) as any;\r\n // }\r\n // return null;\r\n // }\r\n\r\n async decryptMeta<T>(metaHaver: HasCipherMeta): Promise<T> {\r\n if (metaHaver.cipherMeta) {\r\n const key = await this.keyGraph.getJwkKey(metaHaver.keyId);\r\n return (await this.encryptionService.decrypt(\r\n key,\r\n JSON.parse(metaHaver.cipherMeta)\r\n )) as any;\r\n }\r\n return null;\r\n }\r\n\r\n // async decryptFile(keyId: string, file: any): Promise<any> {\r\n // const key = await this.keyGraphService.getJwkKey(keyId);\r\n // return (await this.encryptionService.decrypt(key, file, {\r\n // payloadType: 'ArrayBuffer',\r\n // })) as any;\r\n // }\r\n\r\n // // TODO rename this to encrypt() and use as the most common usecase\r\n // async encryptToString(\r\n // key: string | Key | JWK.Key,\r\n // content: any\r\n // ): Promise<string> {\r\n // // Empty string should be encrypted since you want to clear the field.\r\n // // Null is not encrypted because it's not valid JSON in the old JSON spec. Use\r\n // // empty string instead. It'll function as a logic false as well.\r\n // // Note that passing in empty string means it'll be encrypted which verifies\r\n // // it's integrity. But we still want to have a way to set the DB field\r\n // // to NULL, so we explicitly return null when content == null. A null\r\n // // variable in graphql mutation on KC server clears the field to NULL.\r\n // if (content == null) {\r\n // return null;\r\n // }\r\n\r\n // const jwk =\r\n // asJwk(key) || (await this.keyGraphService.getJwkKey(key as string | Key));\r\n // return JSON.stringify(await this.encryptionService.encrypt(jwk, content));\r\n // }\r\n\r\n // // Wraps a symmetric encryption key.\r\n // // Throws exception if wrapping public keys.\r\n // async wrapKey<T>(\r\n // wrappingKey: string | Key | JWK.Key,\r\n // key: JWK.Key\r\n // ): Promise<string> {\r\n // if (!isSymmetricKey(key)) {\r\n // throw new LrBadArgumentException(\r\n // 'Only allowing wrapping of symmetric keys.'\r\n // );\r\n // }\r\n\r\n // return this.encryptToString(wrappingKey, key.toJSON(true));\r\n // }\r\n\r\n // // TODO\r\n // // async wrapPublicKey<T>();\r\n // // async wrapPrivateKey<T>();\r\n\r\n async doubleWrapContent(\r\n secureContent: any,\r\n categoryIds: string[],\r\n fileContent?: ArrayBuffer\r\n ) {\r\n const key = await this.keyFactory.createKey();\r\n\r\n const wrappedContent = await this.wrapContent(\r\n key.toJSON(true),\r\n categoryIds\r\n );\r\n\r\n return {\r\n rootKey: wrappedContent.rootKey,\r\n wrappedKeys: wrappedContent.wrappedKeys,\r\n doubleWrappedKey: wrappedContent.cipherMeta,\r\n cipherMeta: secureContent\r\n ? JSON.stringify(\r\n await this.encryptionService.encrypt(key, secureContent)\r\n )\r\n : null,\r\n cipherFileContent: fileContent\r\n ? JSON.stringify(await this.encryptionService.encrypt(key, fileContent))\r\n : null,\r\n };\r\n }\r\n\r\n async reWrapContent(keyId: string, secureContent: any) {\r\n const key = await this.keyGraph.getJwkKey(keyId);\r\n const newKey = await this.keyFactory.createKey();\r\n\r\n return {\r\n doubleWrappedKey: JSON.stringify(\r\n await this.encryptionService.encrypt(key, newKey.toJSON(true))\r\n ),\r\n cipherMeta: secureContent\r\n ? JSON.stringify(\r\n await this.encryptionService.encrypt(newKey, secureContent)\r\n )\r\n : null,\r\n };\r\n }\r\n\r\n async wrapContent(\r\n secureContent: any,\r\n categoryIds?: string[]\r\n ): Promise<WrappedContent> {\r\n const key = await this.keyFactory.createKey();\r\n\r\n let wrappedKeys: WrappingKey[];\r\n let rootWrappingKey: WrappingKey;\r\n\r\n if (categoryIds && categoryIds.length) {\r\n wrappedKeys = await Promise.all(\r\n categoryIds.map(async (categoryId) => {\r\n const parentKey = await this.getCategoryKeyId(categoryId);\r\n const wrappedKey = JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n parentKey.key,\r\n key.toJSON(true)\r\n )\r\n );\r\n return {\r\n directoryId: categoryId,\r\n wrappingKeyId: parentKey.keyId,\r\n wrappedKey,\r\n };\r\n })\r\n );\r\n } else {\r\n // Adding to root directory\r\n const rootKey = this.keyService.getCurrentRootKey();\r\n const wrappedKey = JSON.stringify(\r\n await this.encryptionService.encrypt(rootKey.jwk, key.toJSON(true))\r\n );\r\n rootWrappingKey = {\r\n wrappingKeyId: rootKey.id,\r\n wrappedKey,\r\n };\r\n }\r\n\r\n return {\r\n key,\r\n rootKey: rootWrappingKey,\r\n wrappedKeys,\r\n cipherMeta: secureContent\r\n ? JSON.stringify(\r\n await this.encryptionService.encrypt(key, secureContent)\r\n )\r\n : null,\r\n };\r\n }\r\n\r\n async wrapContentWithKey(\r\n secureContent: any,\r\n keyId: string\r\n ): Promise<WrappedContent> {\r\n const key = await this.keyFactory.createKey();\r\n\r\n const wrappedKey = await this.keyGraph.encryptToString(\r\n keyId,\r\n key.toJSON(true)\r\n );\r\n\r\n return {\r\n key,\r\n rootKey: {\r\n wrappingKeyId: keyId,\r\n wrappedKey,\r\n },\r\n cipherMeta: secureContent\r\n ? JSON.stringify(\r\n await this.encryptionService.encrypt(key, secureContent)\r\n )\r\n : null,\r\n };\r\n }\r\n\r\n private async getCategoryKeyId(\r\n categoryId: string\r\n ): Promise<{ keyId: string; key: any }> {\r\n const { category } = await this.lrApollo.query<any>({\r\n query: GetCategoryKeyIdQuery,\r\n variables: {\r\n id: categoryId,\r\n },\r\n });\r\n\r\n return {\r\n keyId: category.keyId,\r\n key: await this.keyGraph.getJwkKey(category.keyId),\r\n };\r\n }\r\n}\r\n","import { KeyGraphField } from '../_common/queries.gql';\r\nimport gql from 'graphql-tag';\r\n\r\nexport const ContactCardFields = `\r\nid\r\npublicData\r\npublicSearchable\r\ncipherData\r\nkey {\r\n id\r\n}\r\n`;\r\n\r\nexport const ContactCardQuery = gql`\r\nquery ContactCardQuery(\r\n$id: LrRelayIdInput!\r\n) {\r\ncontactCard (\r\n id: $id\r\n) {\r\n ${ContactCardFields}\r\n}\r\n${KeyGraphField}\r\n}`;\r\n\r\nexport const SearchContactCardQuery = gql`\r\nquery SearchContactCardQuery(\r\n $publicSearchable: LrJSONFilter!\r\n) {\r\n searchContactCards(\r\n publicSearchable: $publicSearchable\r\n orderBy: \"created\"\r\n ) {\r\n edges {\r\n node {\r\n ${ContactCardFields}\r\n }\r\n }\r\n }\r\n ${KeyGraphField}\r\n}`;\r\n\r\nexport const ContactCardListQuery = gql`\r\nquery ContactCardListQuery {\r\n contactCards(\r\n orderBy: \"created\"\r\n ) {\r\n edges {\r\n node {\r\n ${ContactCardFields}\r\n }\r\n }\r\n }\r\n ${KeyGraphField}\r\n}`;\r\n\r\nexport const CreateContactCardMutation = gql`\r\nmutation CreateContactCardMutation(\r\n $input: CreateContactCardInput!\r\n) {\r\n createContactCard(input: $input) {\r\n contactCard {\r\n ${ContactCardFields}\r\n }\r\n }\r\n}`;\r\n\r\nexport const UpdateContactCardMutation = gql`\r\nmutation UpdateContactCardMutation(\r\n $input: UpdateContactCardInput!\r\n) {\r\n updateContactCard(input: $input) {\r\n contactCard {\r\n ${ContactCardFields}\r\n }\r\n }\r\n}`;\r\n\r\nexport const DeleteContactCardMutation = gql`\r\n mutation DeleteContactCardMutation($input: DeleteContactCardInput!) {\r\n deleteContactCard(input: $input) {\r\n id\r\n }\r\n }\r\n`;\r\n","import gql from 'graphql-tag';\r\n\r\nexport const CreateStripeCheckoutSessionMutation = gql`\r\n mutation CreateStripeCheckoutSession(\r\n $priceId: String!\r\n $successUrl: String!\r\n $cancelUrl: String!\r\n ) {\r\n createStripeCheckoutSession(\r\n input: {\r\n priceId: $priceId\r\n successUrl: $successUrl\r\n cancelUrl: $cancelUrl\r\n }\r\n ) {\r\n sessionId\r\n }\r\n }\r\n`;\r\n\r\nexport const CreateStripeBillingPortalSessionMutation = gql`\r\n mutation CreateStripeBillingPortalSession($returnUrl: String!) {\r\n createStripeBillingPortalSession(input: { returnUrl: $returnUrl }) {\r\n sessionUrl\r\n }\r\n }\r\n`;\r\n\r\nexport const planFields = `\r\n name\r\n data\r\n state\r\n`;\r\n\r\nexport const CreateUserIssuedPlanMutation = gql`\r\nmutation CreateUserIssuedPlan($input: CreateUserIssuedPlanInput!){\r\n createUserIssuedPlan(input: $input) {\r\n userIssuedPlan {\r\n id\r\n plan {\r\n ${planFields}\r\n }\r\n token\r\n tokenExpiryTime\r\n planPeriodEnd\r\n planPeriodEndAfterSeconds\r\n }\r\n }\r\n}`;\r\n\r\nexport const DeleteUserIssuedPlanMutation = gql`\r\n mutation DeleteUserIssuedPlan($input: DeleteUserIssuedPlanInput!) {\r\n deleteUserIssuedPlan(input: $input) {\r\n id\r\n }\r\n }\r\n`;\r\n\r\nexport const UserIssuablePlansQuery = gql`\r\nquery UserIssuablePlans {\r\n userIssuablePlans {\r\n plan {\r\n ${planFields}\r\n }\r\n }\r\n}\r\n`;\r\n\r\n// Put other fields in as needed.\r\nexport const UserIssuedPlansQuery = gql`\r\n query UserIssuedPlans {\r\n userIssuedPlans {\r\n edges {\r\n node {\r\n id\r\n }\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UserIssuedPlanQuery = gql`\r\nquery UserIssuedPlan(\r\n $id: LrRelayIdInput!\r\n $token: String\r\n) {\r\n userIssuedPlan(\r\n id: $id\r\n token: $token\r\n ) {\r\n id\r\n plan {\r\n ${planFields}\r\n }\r\n planPeriodEnd\r\n planPeriodEndAfterSeconds\r\n }\r\n}\r\n`;\r\n\r\nexport const AssociateUserIssuedPlanMutation = gql`\r\nmutation AssociateUserIssuedPlan($input: AssociateUserIssuedPlanInput!){\r\n associateUserIssuedPlan(input: $input) {\r\n userPlan {\r\n id\r\n plan {\r\n ${planFields}\r\n }\r\n periodEnd\r\n }\r\n }\r\n}`;\r\n\r\nexport const UserPlansQuery = gql`\r\nquery UserPlans {\r\n userPlans {\r\n id\r\n periodEnd\r\n plan {\r\n ${planFields}\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport const StripeQuery = gql`\r\n query Stripe {\r\n stripe {\r\n id\r\n customer\r\n }\r\n }\r\n`;\r\n","import { Injectable } from '@angular/core';\r\nimport {\r\n CreateStripeCheckoutSessionMutation,\r\n CreateStripeBillingPortalSessionMutation,\r\n UserIssuablePlansQuery,\r\n CreateUserIssuedPlanMutation,\r\n DeleteUserIssuedPlanMutation,\r\n UserIssuedPlansQuery,\r\n AssociateUserIssuedPlanMutation,\r\n UserPlansQuery,\r\n StripeQuery,\r\n UserIssuedPlanQuery,\r\n} from './plan.gql';\r\nimport { LrApolloService } from '../api/lr-apollo.service';\r\nimport {\r\n StripeCheckoutSession,\r\n StripeBillingPortalSession,\r\n UserIssuablePlan,\r\n UserIssuedPlan,\r\n UserPlan,\r\n} from './plan.types';\r\nimport { LrBadArgumentException } from '../_common/exceptions';\r\n\r\nexport function mapUserPlans(userPlans: any[]): UserPlan[] {\r\n return userPlans.map((t) => ({\r\n ...t,\r\n periodEnd: t.periodEnd && new Date(t.periodEnd),\r\n subscription: { id: t.stripe?.subscriptionId },\r\n }));\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class PlanService {\r\n constructor(private lrApollo: LrApolloService) {}\r\n\r\n async createStripeCheckoutSession(input: {\r\n priceId: string;\r\n successUrl: string;\r\n cancelUrl: string;\r\n }): Promise<StripeCheckoutSession> {\r\n const res = await this.lrApollo.mutate<{\r\n createStripeCheckoutSession: any;\r\n }>({\r\n mutation: CreateStripeCheckoutSessionMutation,\r\n variables: {\r\n ...input,\r\n },\r\n });\r\n return {\r\n id: res.createStripeCheckoutSession.sessionId,\r\n };\r\n }\r\n\r\n async createStripeBillingPortalSession(\r\n returnUrl: string\r\n ): Promise<StripeBillingPortalSession> {\r\n const res = await this.lrApollo.mutate<{\r\n createStripeBillingPortalSession: any;\r\n }>({\r\n mutation: CreateStripeBillingPortalSessionMutation,\r\n variables: {\r\n returnUrl,\r\n },\r\n });\r\n return {\r\n url: res.createStripeBillingPortalSession.sessionUrl,\r\n };\r\n }\r\n\r\n async getUserIssuablePlans(): Promise<UserIssuablePlan[]> {\r\n const { userIssuablePlans } = await this.lrApollo.query<{\r\n userIssuablePlans: any;\r\n }>({\r\n query: UserIssuablePlansQuery,\r\n });\r\n\r\n return userIssuablePlans;\r\n }\r\n\r\n async createUserIssuedPlan({\r\n planName,\r\n tokenExpiryTime,\r\n planPeriodEnd,\r\n planPeriodEndAfterSeconds,\r\n }: {\r\n planName: string;\r\n tokenExpiryTime: Date;\r\n planPeriodEnd?: Date;\r\n planPeriodEndAfterSeconds?: number;\r\n }): Promise<UserIssuedPlan> {\r\n if (planPeriodEnd == null && planPeriodEndAfterSeconds == null) {\r\n throw new LrBadArgumentException(\r\n 'Must specify either \"planPeriodEnd\" or \"planPeriodEndAfterSeconds\"'\r\n );\r\n }\r\n\r\n const { createUserIssuedPlan } = await this.lrApollo.mutate<any>({\r\n mutation: CreateUserIssuedPlanMutation,\r\n variables: {\r\n input: {\r\n planName,\r\n tokenExpiryTime: tokenExpiryTime.toISOString(),\r\n planPeriodEnd: planPeriodEnd && planPeriodEnd.toISOString(),\r\n planPeriodEndAfterSeconds,\r\n },\r\n },\r\n });\r\n\r\n const { userIssuedPlan } = createUserIssuedPlan;\r\n\r\n return {\r\n ...userIssuedPlan,\r\n tokenExpiryTime: new Date(userIssuedPlan.tokenExpiryTime),\r\n planPeriodEnd: new Date(userIssuedPlan.planPeriodEnd),\r\n };\r\n }\r\n\r\n async deleteUserIssuedPlan(id: string): Promise<void> {\r\n return await this.lrApollo.mutate<any>({\r\n mutation: DeleteUserIssuedPlanMutation,\r\n variables: {\r\n input: {\r\n id,\r\n },\r\n },\r\n });\r\n }\r\n\r\n async getUserIssuedPlans(): Promise<any[]> {\r\n const { userIssuedPlans } = await this.lrApollo.query<any>({\r\n query: UserIssuedPlansQuery,\r\n });\r\n\r\n return userIssuedPlans.edges.map((edge) => edge.node);\r\n }\r\n\r\n async getUserIssuedPlan(id: string, token?: string): Promise<any> {\r\n const { userIssuedPlan } = await this.lrApollo.query<any>({\r\n query: UserIssuedPlanQuery,\r\n variables: {\r\n id,\r\n token,\r\n },\r\n });\r\n\r\n return userIssuedPlan;\r\n }\r\n\r\n async associateUserIssuedPlan({\r\n id,\r\n token,\r\n }: {\r\n id: string;\r\n token: string;\r\n }): Promise<UserPlan> {\r\n const { associateUserIssuedPlan } = await this.lrApollo.query<any>({\r\n query: AssociateUserIssuedPlanMutation,\r\n variables: {\r\n input: {\r\n id,\r\n token,\r\n },\r\n },\r\n });\r\n\r\n const { userPlan } = associateUserIssuedPlan;\r\n\r\n return {\r\n ...userPlan,\r\n periodEnd: new Date(userPlan.periodEnd),\r\n };\r\n }\r\n\r\n async getUserPlans(): Promise<UserPlan[]> {\r\n const { userPlans } = await this.lrApollo.query<any>({\r\n query: UserPlansQuery,\r\n });\r\n\r\n return mapUserPlans(userPlans);\r\n }\r\n\r\n async getPlanType(subscriptionId: string): Promise<string> {\r\n const stripe: any = await this.getStripe();\r\n return stripe.customer.subscriptions.data.filter(\r\n (sub) => sub.id === subscriptionId\r\n )[0].items.data[0].plan.interval;\r\n }\r\n\r\n async getStripe(): Promise<{ id: string; customer: object }> {\r\n const { stripe } = await this.lrApollo.query<any>({\r\n query: StripeQuery,\r\n });\r\n\r\n return stripe;\r\n }\r\n}\r\n","import { HttpClient } from '@angular/common/http';\r\nimport { Inject, Injectable } from '@angular/core';\r\nimport { LrApolloService } from '../api/lr-apollo.service';\r\nimport { LifeReadyConfig, LR_CONFIG } from '../life-ready.config';\r\nimport {\r\n CurrentUserQuery,\r\n CurrentUserQueryType,\r\n UpdateContactCardMutation,\r\n CreateContactCardMutation,\r\n} from './profile.gql';\r\nimport {\r\n ApiCurrentUser,\r\n PassIdpApiResult,\r\n MainContactCard,\r\n ApiContactCard,\r\n MainContactCardFields,\r\n MainContactCardPlainFields,\r\n ContactCardName,\r\n} from './profile.types';\r\nimport { KeyMetaService } from '../cryptography/key-meta.service';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { ContactCard } from '../api/contact-card.service';\r\nimport {\r\n ContactCardListQuery,\r\n DeleteContactCardMutation,\r\n} from '../api/contact-card.gql';\r\nimport { mapUserPlans } from '../plan/plan.service';\r\nimport { UserPlan } from '../plan/plan.types';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class ProfileService {\r\n constructor(\r\n @Inject(LR_CONFIG) private config: LifeReadyConfig,\r\n private http: HttpClient,\r\n private lrApollo: LrApolloService,\r\n private keyService: KeyService,\r\n private keyMetaService: KeyMetaService,\r\n private keyGraph: KeyGraphService,\r\n private encryptionService: EncryptionService\r\n ) {}\r\n\r\n async getPassIdpParams(emailOrPhone: string): Promise<PassIdpApiResult> {\r\n return await this.http\r\n .get<PassIdpApiResult>(\r\n `${\r\n this.config.authUrl\r\n }users/pass-idp-params/?login_name=${encodeURIComponent(emailOrPhone)}`\r\n )\r\n .toPromise();\r\n }\r\n\r\n async getCurrentUser(): Promise<{\r\n currentUser: ApiCurrentUser;\r\n contactCard: ApiContactCard;\r\n userPlans: UserPlan[];\r\n }> {\r\n const {\r\n currentUser,\r\n contactCards,\r\n userPlans,\r\n } = await this.lrApollo.query<CurrentUserQueryType>({\r\n query: CurrentUserQuery,\r\n });\r\n\r\n const contactCard = contactCards.edges.map((x) => x.node)[0];\r\n\r\n return {\r\n currentUser,\r\n contactCard,\r\n userPlans: mapUserPlans(userPlans),\r\n };\r\n }\r\n\r\n async decryptContactCard(\r\n contactCard: ApiContactCard\r\n ): Promise<MainContactCard> {\r\n if (!contactCard) {\r\n return null;\r\n }\r\n\r\n const details = await this.keyGraph.decryptFromString<any>(\r\n contactCard.key.id,\r\n contactCard.cipherData\r\n );\r\n\r\n return {\r\n id: contactCard.id,\r\n keyId: contactCard.key.id,\r\n ...details,\r\n };\r\n }\r\n\r\n async updateDetails(\r\n id: string,\r\n keyId: string,\r\n fields: MainContactCardFields\r\n ): Promise<void> {\r\n await (id\r\n ? this.updateContactCard(id, keyId, fields)\r\n : this.createContactCard(fields));\r\n }\r\n\r\n private async prepareContactCardInput(\r\n contactCard: MainContactCardFields\r\n ): Promise<any> {\r\n const sigPxk = await this.keyService.getCurrentSigPxk();\r\n\r\n const publicDataSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, '')\r\n );\r\n const publicSearchableSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, '')\r\n );\r\n\r\n const plainDataJson: MainContactCardPlainFields = {\r\n // contactCard.name.value may have additional attributes such as the id of the contact card.\r\n // So we create a clean version. Otherwise it will fail server checks.\r\n name: new ContactCardName(contactCard.name.value),\r\n };\r\n const plainDataSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, plainDataJson)\r\n );\r\n\r\n return {\r\n sigPxkId: sigPxk.id,\r\n publicDataSig,\r\n publicSearchableSig,\r\n plainDataSig,\r\n };\r\n }\r\n\r\n private async createContactCard(\r\n contactCard: MainContactCardFields\r\n ): Promise<ApiContactCard> {\r\n const input = await this.prepareContactCardInput(contactCard);\r\n\r\n const { rootKey, cipherMeta } = await this.keyMetaService.wrapContent(\r\n contactCard\r\n );\r\n\r\n const data = await this.lrApollo.mutate<{\r\n createContactCard: { contactCard: ApiContactCard };\r\n }>({\r\n mutation: CreateContactCardMutation,\r\n variables: {\r\n input: {\r\n ...input,\r\n cipherData: cipherMeta,\r\n wrappingKeyId: rootKey.wrappingKeyId,\r\n wrappedKey: rootKey.wrappedKey,\r\n default: true, // Use this contact card as default contact card.\r\n },\r\n },\r\n });\r\n return data.createContactCard.contactCard;\r\n }\r\n\r\n private async updateContactCard(\r\n id: string,\r\n keyId: string,\r\n contactCard: MainContactCardFields\r\n ): Promise<ApiContactCard> {\r\n const input = await this.prepareContactCardInput(contactCard);\r\n\r\n const cipherData = await this.keyGraph.encryptToString(keyId, contactCard);\r\n\r\n const data = await this.lrApollo.mutate<{\r\n updateContactCard: { contactCard: ApiContactCard };\r\n }>({\r\n mutation: UpdateContactCardMutation,\r\n variables: {\r\n input: {\r\n ...input,\r\n id,\r\n cipherData,\r\n },\r\n },\r\n });\r\n return data.updateContactCard.contactCard;\r\n }\r\n\r\n async decryptContactCardEdges(edges): Promise<ContactCard[]> {\r\n return Promise.all(\r\n edges.map(async (edge: any) => {\r\n const cc = edge.node as ContactCard;\r\n return await this.decryptContactCard(cc);\r\n })\r\n );\r\n }\r\n\r\n async getContactCards(): Promise<ContactCard[]> {\r\n const data = await this.lrApollo.query<any>({\r\n query: ContactCardListQuery,\r\n });\r\n\r\n return await this.decryptContactCardEdges(data.contactCards.edges);\r\n }\r\n\r\n async deleteContactCard(id: string): Promise<string> {\r\n const data = await this.lrApollo.mutate<any>({\r\n mutation: DeleteContactCardMutation,\r\n variables: {\r\n input: {\r\n id,\r\n },\r\n },\r\n });\r\n\r\n return data.deleteContactCard.id;\r\n }\r\n\r\n async signOut(): Promise<void> {\r\n await this.http\r\n .post(`${this.config.authUrl}auth/sign-out/`, null, {\r\n withCredentials: true,\r\n responseType: 'text',\r\n })\r\n .toPromise();\r\n }\r\n}\r\n","import { CognitoUser } from '@aws-amplify/auth';\r\nimport { JWK } from 'node-jose';\r\nimport { TpPasswordResetUserNode } from '../api/types';\r\nimport {\r\n PassIdpParams,\r\n PassKeyParams,\r\n} from '../cryptography/cryptography.types';\r\nimport { UserPlan } from '../plan/plan.types';\r\nimport { CurrentUserKey, MainContactCard } from '../users/profile.types';\r\nimport { UserDelete } from '../users/user.types';\r\n\r\nexport interface PassKeyBundle {\r\n passKeyParams: PassKeyParams;\r\n passKey: JWK.Key;\r\n passIdpParams: PassIdpParams;\r\n passIdp: JWK.Key;\r\n passIdpVerifier: JWK.Key;\r\n wrappedPassIdpVerifierPrk: object;\r\n}\r\n\r\nexport class CognitoChallengeUser extends CognitoUser {\r\n recoveryStatus: RecoveryStatus;\r\n challengeName: 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA';\r\n challengeParam: any;\r\n isTpPasswordResetUser = false;\r\n}\r\n\r\nexport enum FeatureAction {\r\n // Just the one for now\r\n ACCESS = 'access',\r\n}\r\n\r\nexport class Features {\r\n myVault: FeatureAction[];\r\n tpVault: FeatureAction[];\r\n shareVault: FeatureAction[];\r\n}\r\n\r\nexport class CurrentUser {\r\n id: string;\r\n sub: string;\r\n username: string;\r\n currentUserKey: CurrentUserKey;\r\n email: string;\r\n emailVerified: boolean;\r\n phone: string;\r\n phoneVerified: boolean;\r\n getAccessJwtToken: () => string;\r\n contactCard: MainContactCard;\r\n userDelete?: UserDelete;\r\n userPlans: UserPlan[];\r\n features: Features;\r\n hasTPVaultAccess: boolean;\r\n sessionEncryptionKey: string;\r\n}\r\n\r\nexport interface TpPasswordResetUser extends TpPasswordResetUserNode {\r\n sub: string;\r\n}\r\n\r\nexport class LoginResult {\r\n hasChallenge: boolean;\r\n challenge?: CognitoChallengeUser;\r\n user?: CurrentUser;\r\n resetUser?: TpPasswordResetUserNode;\r\n}\r\n\r\nexport class RegisterResult {\r\n username: string;\r\n userId: string;\r\n preSignUpToken: string;\r\n userSub: string;\r\n}\r\n\r\nexport enum RecoveryStatus {\r\n NONE = 'none',\r\n NEW_PASSWORD = 'new-password',\r\n OLD_PASSWORD = 'old-password',\r\n}\r\n","// Abstract Syntax Tree\r\n\r\nimport {\r\n DocumentNode,\r\n FieldNode,\r\n FragmentDefinitionNode,\r\n NameNode,\r\n OperationDefinitionNode,\r\n OperationTypeNode,\r\n} from 'graphql';\r\nimport gql from 'graphql-tag';\r\nimport { LrBadArgumentException, LrBadLogicException } from './exceptions';\r\n\r\nexport function getAstOperation(\r\n astDocument,\r\n operation: OperationTypeNode\r\n): OperationDefinitionNode {\r\n const operations = astDocument.definitions.filter(\r\n (def: OperationDefinitionNode) => def.kind === 'OperationDefinition'\r\n );\r\n\r\n if (operations.length > 1) {\r\n throw new LrBadLogicException(\r\n `There can be only one '${operation}' operation, instead there are ${operations.length}`\r\n );\r\n }\r\n\r\n return operations[0];\r\n}\r\n\r\nexport function getQuery(doc: DocumentNode): OperationDefinitionNode {\r\n return getAstOperation(doc, 'query');\r\n}\r\n\r\nexport function getMutation(doc: DocumentNode): OperationDefinitionNode {\r\n return getAstOperation(doc, 'mutation');\r\n}\r\n\r\nexport function getFragments(doc: DocumentNode): FragmentDefinitionNode[] {\r\n return doc.definitions.filter(\r\n (def) => def.kind === 'FragmentDefinition'\r\n ) as FragmentDefinitionNode[];\r\n}\r\n\r\nexport function getFragment(astDocument: DocumentNode): FragmentDefinitionNode {\r\n const fragments = getFragments(astDocument);\r\n if (fragments.length > 1) {\r\n throw new LrBadArgumentException(\r\n 'GraphQL document can only contain one fragment.'\r\n );\r\n }\r\n return fragments[0];\r\n}\r\n\r\nexport function name(value: string): NameNode {\r\n return {\r\n kind: 'Name',\r\n value,\r\n };\r\n}\r\n\r\nexport function getAliasOrName(field: FieldNode) {\r\n return field.alias?.value || field.name.value;\r\n}\r\n\r\n// Collocates the type with the document.\r\n/* tslint:disable:no-empty-interface */\r\nexport interface TypedDocumentNode<T> extends DocumentNode {}\r\n\r\nexport function gqlTyped<T = any>(\r\n literals: ReadonlyArray<string> | Readonly<string>,\r\n ...placeholders: any[]\r\n): TypedDocumentNode<T> {\r\n return gql(literals, ...placeholders) as TypedDocumentNode<T>;\r\n}\r\n","import gql from 'graphql-tag';\r\nimport { gqlTyped } from '../_common/ast';\r\n\r\nexport const PasswordChangeRequestMutation = gql`\r\n mutation {\r\n passwordChangeRequest(input: {}) {\r\n challenge\r\n passKeys {\r\n id\r\n passIdpParams\r\n wrappedPassIdpVerifierPrk\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const PasswordChangeMutation = gql`\r\n mutation PasswordChange($input: PasswordChangeInput!) {\r\n passwordChange(input: $input) {\r\n token\r\n newPassKey {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const PasswordChangeConfigQuery = gql`\r\n query PasswordChangeConfigQuery {\r\n passwordChangeConfig {\r\n maxAuthAgeSeconds\r\n authTime\r\n serverTime\r\n }\r\n }\r\n`;\r\n\r\nexport interface SetSessionEncryptionKeyMutation {\r\n setSessionEncryptionKey: {\r\n sessionEncryptionKey: string;\r\n };\r\n}\r\nexport const SetSessionEncryptionKeyMutation = gqlTyped<SetSessionEncryptionKeyMutation>`\r\nmutation SetSessionEncryptionKeyMutation($input: SetSessionEncryptionKeyInput!) {\r\n setSessionEncryptionKey(input: $input) {\r\n sessionEncryptionKey\r\n }\r\n}\r\n`;\r\n\r\nexport interface ClearSessionEncryptionKeyMutation {\r\n clearSessionEncryptionKey: {\r\n sessionEncryptionKey: string;\r\n };\r\n}\r\nexport const ClearSessionEncryptionKeyMutation = gqlTyped<ClearSessionEncryptionKeyMutation>`\r\nmutation ClearSessionEncryptionKeyMutation {\r\n clearSessionEncryptionKey(input: {}) {\r\n sessionEncryptionKey\r\n }\r\n}\r\n`;\r\n","export enum Config {\r\n TIMEOUT = 0.01, // seconds, min value 0.01, after state is idle, wait for TIMEOUT seconds before taking action\r\n IDLE = 60 * 20, // seconds, period of inactivity to consider state as idle\r\n KEEP_ALIVE_INTERVAL = 60 * 1, // seconds, triggered on a regular basis while active (i.e. while not idling)\r\n}\r\n\r\nexport interface KeepaliveResult {\r\n session: {\r\n expires_after_seconds: number;\r\n };\r\n}\r\n","import { Inject, Injectable } from '@angular/core';\r\nimport { Idle, DEFAULT_INTERRUPTSOURCES } from '@ng-idle/core';\r\nimport { Keepalive } from '@ng-idle/keepalive';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport {\r\n LrBadArgumentException,\r\n LrBadStateException,\r\n} from '../_common/exceptions';\r\nimport { LifeReadyConfig, LR_CONFIG } from '../life-ready.config';\r\nimport { HttpClient } from '@angular/common/http';\r\nimport { Config, KeepaliveResult } from './idle.types';\r\nimport { Key } from '../cryptography/cryptography.types';\r\nimport { CognitoUser } from '@aws-amplify/auth';\r\nimport { AuthClass } from '@aws-amplify/auth/lib-esm/Auth';\r\n\r\nexport interface IdleServiceInit {\r\n // TODO: this should be EventEmitter instead of a callback.\r\n onTimeout?: (() => any) | (() => Promise<any>) | null;\r\n onKeepalive?: (() => any) | (() => Promise<any>) | null;\r\n idleSec?: number;\r\n timeoutSec?: number;\r\n keepAliveIntervalSec?: number;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class IdleService {\r\n private readonly IDLE_EXPIRY_KEY = 'ng2Idle.main.expiry';\r\n private readonly IDLING_KEY = 'ng2Idle.main.idling';\r\n\r\n private initCalled = false;\r\n private onTimeout: (() => any) | (() => Promise<any>) | null;\r\n private onKeepalive: (() => any) | (() => Promise<any>) | null;\r\n\r\n constructor(\r\n @Inject(LR_CONFIG) private config: LifeReadyConfig,\r\n private http: HttpClient,\r\n private idle: Idle,\r\n private keepalive: Keepalive,\r\n private keyService: KeyService,\r\n private auth: AuthClass\r\n ) {}\r\n\r\n private assertInit(): void {\r\n if (!this.initCalled) {\r\n throw new LrBadStateException('Call IdleService.init() first.');\r\n }\r\n }\r\n\r\n public async init(params?: IdleServiceInit): Promise<void> {\r\n if (this.initCalled) {\r\n throw new LrBadStateException(\r\n 'IdleService.init() can only be called once. IdleService.start() calls init() with default values if init() has not been called yet.'\r\n );\r\n }\r\n\r\n this.initCalled = true;\r\n\r\n // Defaults\r\n params = {\r\n onTimeout: null,\r\n onKeepalive: null,\r\n idleSec: Config.IDLE,\r\n timeoutSec: Config.TIMEOUT,\r\n keepAliveIntervalSec: Config.KEEP_ALIVE_INTERVAL,\r\n ...params,\r\n };\r\n\r\n // If timeoutSec == 0 then the onTimeout() callback is never called.\r\n if (params.timeoutSec < 0.01) {\r\n throw new LrBadArgumentException(\r\n 'Minimum value for IdleService.init({ timeoutSec }) is 0.01'\r\n );\r\n }\r\n\r\n this.onTimeout = params.onTimeout;\r\n this.onKeepalive = params.onKeepalive;\r\n\r\n // ------------------------------------------------------------------------\r\n // Setup Idle\r\n // ------------------------------------------------------------------------\r\n // sets an idle timeout of 5 seconds, for testing purposes.\r\n this.idle.setIdle(params.idleSec);\r\n // sets a timeout period of 5 seconds. after 10 seconds of inactivity, the user will be considered timed out.\r\n this.idle.setTimeout(params.timeoutSec);\r\n // sets the default interrupts, in this case, things like clicks, scrolls, touches to the document\r\n this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);\r\n\r\n this.idle.onIdleEnd.subscribe(() => console.log('Idle stopped'));\r\n this.idle.onIdleStart.subscribe(() => console.log('Idle started'));\r\n\r\n this.idle.onTimeout.subscribe(async () => {\r\n console.log('Idle timed out');\r\n this.reset();\r\n await Promise.resolve(this.onTimeout && this.onTimeout());\r\n });\r\n this.idle.onTimeoutWarning.subscribe((countdown: any) =>\r\n console.log(`Will timeout in ${countdown} seconds!`)\r\n );\r\n\r\n // ------------------------------------------------------------------------\r\n // Setup Keepalive\r\n // ------------------------------------------------------------------------\r\n // Ref: https://github.com/moribvndvs/ng2-idle#readme\r\n // ng-idle will instruct @ng-idle/keepalive to ping while the user is active, and stop once\r\n // they go idle or time out. When the user resumes activity or the idle state is reset, it will\r\n // ping immediately and then resume pinging.\r\n this.keepalive.interval(params.keepAliveIntervalSec);\r\n console.log(\r\n `Keep alive interval set at: ${Config.KEEP_ALIVE_INTERVAL} seconds`\r\n );\r\n\r\n this.keepalive.onPing.subscribe(() => this.onPing());\r\n\r\n // If the browser tab has been closed for a period longer thant the inactivity\r\n // period, then we should logout right from the start.\r\n const idleExpiry = localStorage.getItem(this.IDLE_EXPIRY_KEY);\r\n if (\r\n idleExpiry &&\r\n parseInt(idleExpiry, 10) + this.idle.getTimeout() * 1000 < Date.now()\r\n ) {\r\n this.reset();\r\n await Promise.resolve(this.onTimeout && this.onTimeout());\r\n }\r\n }\r\n\r\n public async keepalivePost(): Promise<{\r\n expiresAfterSeconds: number;\r\n keepaliveResult: KeepaliveResult;\r\n }> {\r\n // currentAuthenticatedUser() refreshes the access token if required.\r\n const cognitoUser: CognitoUser = await this.auth.currentAuthenticatedUser();\r\n\r\n const keepaliveResult = await this.http\r\n .post<KeepaliveResult>(`${this.config.authUrl}auth/keepalive/`, null, {\r\n withCredentials: true, // /auth/keepalive/ will be extending the sessions cookie.\r\n headers: {\r\n Authorization: `Bearer ${cognitoUser\r\n .getSignInUserSession()\r\n .getAccessToken()\r\n .getJwtToken()}`,\r\n },\r\n })\r\n .toPromise();\r\n\r\n return {\r\n keepaliveResult,\r\n expiresAfterSeconds:\r\n this.idle.getIdle() +\r\n this.idle.getTimeout() +\r\n this.keepalive.interval(),\r\n };\r\n }\r\n\r\n public async persistMasterKey(masterKey: Key): Promise<void> {\r\n // The keepalive API call extends the server-side session, the session cookie expiry, refresh key cookie\r\n // expiry, and returns the session expiry.\r\n // NOTE Use time delta rather than absolute time, since client clock and server clock maybe\r\n // out of sync. We can't use the serverTime() functionality because the cookie expiry still\r\n // run on local clock.\r\n const { expiresAfterSeconds } = await this.keepalivePost();\r\n\r\n // Persist the derived passKey\r\n await this.keyService.persistMasterKey(masterKey, expiresAfterSeconds);\r\n\r\n console.log('setMasterKey() done');\r\n }\r\n\r\n private async onPing(): Promise<void> {\r\n console.log(\r\n `Keep alive triggered at time: ${Date.now()}. Interval set at: ${this.keepalive.interval()} seconds`\r\n );\r\n\r\n // Keepalive API will extend the session expiry.\r\n const { expiresAfterSeconds } = await this.keepalivePost();\r\n\r\n // Extend the expiry of the persisted key\r\n await this.keyService.setMasterKeyExpiresAfterSeconds(expiresAfterSeconds);\r\n\r\n await Promise.resolve(this.onKeepalive && this.onKeepalive());\r\n }\r\n\r\n public async start(): Promise<void> {\r\n if (!this.initCalled) {\r\n await this.init();\r\n }\r\n\r\n if (this.idle.isRunning()) {\r\n return;\r\n }\r\n\r\n // Ping does not seem to happen right at the start. So we call it explicitly\r\n await this.onPing();\r\n\r\n this.idle.watch();\r\n }\r\n\r\n public stop(): void {\r\n this.idle.stop();\r\n this.reset();\r\n }\r\n\r\n private reset() {\r\n localStorage.removeItem(this.IDLE_EXPIRY_KEY);\r\n localStorage.removeItem(this.IDLING_KEY);\r\n }\r\n}\r\n","import { HttpClient } from '@angular/common/http';\r\nimport { Inject, Injectable } from '@angular/core';\r\nimport { CognitoUser } from '@aws-amplify/auth';\r\nimport { AuthClass } from '@aws-amplify/auth/lib-esm/Auth';\r\nimport { JWK, JWS } from 'node-jose';\r\nimport { ProfileService } from '../users/profile.service';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { LifeReadyConfig, LR_CONFIG } from '../life-ready.config';\r\nimport { LrAuthException, LrBadArgumentException } from '../_common/exceptions';\r\nimport { LrApolloService } from './../api/lr-apollo.service';\r\nimport {\r\n PasswordChangeMutation,\r\n PasswordChangeRequestMutation,\r\n PasswordChangeConfigQuery,\r\n} from './auth.gql';\r\nimport { PassKeyBundle } from './auth.types';\r\nimport { WebCryptoService } from '../cryptography/web-crypto.service';\r\nimport { Duration } from 'moment';\r\nimport * as moment_ from 'moment';\r\nimport { ApiCurrentUser } from '../users/profile.types';\r\nimport { IdleService } from '../auth/idle.service';\r\nimport { KeyFactoryService as KFS } from '../cryptography/key-factory.service';\r\n\r\n// \"why?\" you ask: https://stackoverflow.com/questions/59735280/angular-8-moment-error-cannot-call-a-namespace-moment\r\nconst moment = moment_;\r\n\r\ninterface PasswordChangeRequestMutation {\r\n passwordChangeRequest: {\r\n challenge: {\r\n serverNonce: string;\r\n };\r\n };\r\n}\r\n\r\ninterface PasswordChangeMutation {\r\n passwordChange: {\r\n token: string;\r\n newPassKey: {\r\n id: string;\r\n };\r\n };\r\n}\r\n\r\nexport interface PasswordChangeConfig {\r\n maxAuthAgeSeconds: number;\r\n authTime: string | Date;\r\n serverTime: string | Date;\r\n}\r\n\r\nexport class PasswordCheck {\r\n length?: number;\r\n timeToCrack?: Duration;\r\n passwordExposed?: number;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class PasswordService {\r\n private readonly CLIENT_NONCE_LENGTH = 32;\r\n\r\n constructor(\r\n @Inject(LR_CONFIG) private config: LifeReadyConfig,\r\n private http: HttpClient,\r\n private apollo: LrApolloService,\r\n private auth: AuthClass,\r\n private profileService: ProfileService,\r\n private keyFactory: KFS,\r\n private encryptionService: EncryptionService,\r\n private keyGraph: KeyGraphService,\r\n private webCryptoService: WebCryptoService,\r\n private idleService: IdleService\r\n ) {}\r\n\r\n public async checkPassword(password: string): Promise<PasswordCheck> {\r\n const { years } = this.passwordStrength(password);\r\n\r\n return {\r\n length: password.length,\r\n timeToCrack: moment.duration({ years }),\r\n passwordExposed: await this.getExposureCount(password),\r\n };\r\n }\r\n\r\n public async getExposureCount(password: string): Promise<number> {\r\n const sha1Password = await this.webCryptoService.stringDigest(\r\n 'SHA-1',\r\n password\r\n );\r\n const first5sha1 = sha1Password.substring(0, 5);\r\n\r\n const response = await this.http\r\n .get(`https://api.pwnedpasswords.com/range/${first5sha1}`, {\r\n responseType: 'text',\r\n })\r\n .toPromise();\r\n\r\n const results = new RegExp(\r\n `^(?:${sha1Password.substring(5)}:)(?<count>\\\\d+)$`,\r\n 'im'\r\n ).exec(response);\r\n\r\n if (results) {\r\n return +results.groups.count;\r\n }\r\n return 0;\r\n }\r\n\r\n public getPassIdpString(passIdp: JWK.Key) {\r\n return (passIdp.toJSON(true) as any).k;\r\n }\r\n\r\n public async createPassKeyBundle(password: string): Promise<PassKeyBundle> {\r\n const passIdpParams = await this.keyFactory.createPassIdpParams();\r\n const passIdp = (\r\n await this.keyFactory.derivePassIdp({\r\n password,\r\n ...passIdpParams,\r\n })\r\n ).jwk;\r\n\r\n const passKeyParams = await this.keyFactory.createPassKeyParams();\r\n const passKey = (\r\n await this.keyFactory.derivePassKey({\r\n password,\r\n ...passKeyParams,\r\n })\r\n ).jwk;\r\n\r\n const passIdpVerifier = await this.keyFactory.createPkcSignKey();\r\n\r\n const wrappedPassIdpVerifierPrk = await this.encryptionService.encrypt(\r\n passKey,\r\n passIdpVerifier.toJSON(true)\r\n );\r\n\r\n // There are two formats that the private key can be represented in JWK:\r\n // https://tools.ietf.org/html/rfc8017#page-9\r\n // The second form is an optimization:\r\n // https://crypto.stackexchange.com/questions/19413/what-are-dp-and-dq-in-encryption-by-rsa-in-c\r\n\r\n return {\r\n passKeyParams,\r\n passKey,\r\n passIdpParams,\r\n passIdp,\r\n passIdpVerifier,\r\n wrappedPassIdpVerifierPrk,\r\n };\r\n }\r\n\r\n /**\r\n * We need to allow for interruption of the process at any point. Each API call can be considered\r\n * atomic and either succeeds or fails.\r\n *\r\n * The LR server APIs use semaphore tokens for locking critical operations, so concurrent calls will\r\n * fail.\r\n *\r\n * We assume the worst case for IdP API calls. So we use the semaphore token from LR to prevent\r\n * concurrent calls to IdP APIs, but we have to assume that the IdP API calls will either succeed or\r\n * fail within a reasonable amount of time.\r\n *\r\n * Each location where the server state changes can be a potential point of interruption.\r\n * Potential points of interruption are marked with: --Potential Failure Point--\r\n *\r\n * Places for timeout:\r\n * - Login age too old at call to: verifyPassword()\r\n * - Login age too old at call to: changePasswordMutation()\r\n * - Semaphore token expires at call to: changePasswordComplete()\r\n *\r\n * Tests:\r\n * - Potential Failure Point 1: should be able to restart the process, user remains signed in.\r\n * - Potential Failure Point 2: should enter recovery flow\r\n * - Potential Failure Point 3: should enter recovery flow\r\n * - Potential Failure Point 4: should enter recovery flow\r\n *\r\n */\r\n\r\n public async isLoginRequired(): Promise<boolean> {\r\n const changePasswordConfig = await this.getChangePasswordConfig();\r\n const authTime = moment(changePasswordConfig.authTime);\r\n const serverTime = moment(changePasswordConfig.serverTime);\r\n const duration = moment.duration(serverTime.diff(authTime));\r\n const seconds = duration.asSeconds();\r\n if (seconds > changePasswordConfig.maxAuthAgeSeconds) {\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n public async changePassword(password: string, newPassword: string) {\r\n const cognitoUser: CognitoUser = await this.auth.currentAuthenticatedUser();\r\n\r\n // Validation\r\n // todo: Add this back in\r\n // Note the passIdp will always have a random salt, so will always be different to the current passIdp.\r\n if (password === newPassword) {\r\n throw new LrBadArgumentException(\r\n 'New password is the same as the current one.'\r\n );\r\n }\r\n\r\n const { currentUser } = await this.profileService.getCurrentUser();\r\n\r\n const { passIdp, signedChallenge } = await this.verifyPassword(\r\n password,\r\n currentUser\r\n );\r\n\r\n // --Potential Failure Point 1--\r\n // verifyPassword() asks for a current password challenge hence changes server state.\r\n // Place break points here to test the failure scenarios.\r\n\r\n // Generate the new passIdp\r\n const newPassKey = await this.createPassKeyBundle(newPassword);\r\n\r\n // Re-encrypt master key with new key\r\n const masterKey = await this.keyGraph.getKey(\r\n currentUser.currentUserKey.masterKey.id\r\n );\r\n const newWrappedMasterKey = await this.encryptionService.encrypt(\r\n newPassKey.passKey,\r\n masterKey.jwk.toJSON(true)\r\n );\r\n\r\n // If the IdP change password failed, we need to go into recovery mode by forcing\r\n // a login. We can't logout the user just yet since the IdP password change needs\r\n // the user to be logged in. We _can_ removed any persisted session values for the IdP\r\n // but that seems like too much trouble.\r\n\r\n const { token, newPassKeyId } = await this.changePasswordMutation(\r\n signedChallenge,\r\n currentUser.currentUserKey.masterKey.id,\r\n newWrappedMasterKey,\r\n newPassKey\r\n );\r\n\r\n // --Potential Failure Point 2--\r\n // changePasswordMutation() uploads new keys and obtains a semaphore lock to prevent any other\r\n // clients from performing IdP password change.\r\n\r\n // Now we can do the IdP password change.\r\n // todo: Add this back in\r\n await this.auth.changePassword(\r\n cognitoUser,\r\n this.getPassIdpString(passIdp),\r\n this.getPassIdpString(newPassKey.passIdp)\r\n );\r\n\r\n // --Potential Failure Point 3--\r\n // IdP password change\r\n\r\n // Note that changePassword() could throw an exception for a number of reason. It could throw\r\n // a network timeout for example. But we don't know if it's the response that timed out and\r\n // the idp password change was actually carried out. So we have to be extra conservative and\r\n // only act on a clear success. Otherwise we go into recover mode.\r\n await this.changePasswordComplete(\r\n cognitoUser.getSignInUserSession().getAccessToken().getJwtToken(),\r\n true,\r\n token\r\n );\r\n }\r\n\r\n public async changePasswordComplete(\r\n accessToken: string,\r\n useNewPassword: boolean,\r\n token: string = null\r\n ): Promise<any> {\r\n return this.http\r\n .post(\r\n `${this.config.authUrl}users/password-change-complete/`,\r\n {\r\n use_new_password: useNewPassword,\r\n ...(token && { token }),\r\n },\r\n {\r\n headers: {\r\n Authorization: `Bearer ${accessToken}`,\r\n },\r\n }\r\n )\r\n .toPromise();\r\n }\r\n\r\n private async getVerifierPrK(\r\n passKey: JWK.Key,\r\n wrappedPrK: object\r\n ): Promise<JWK.Key> {\r\n try {\r\n const prkJson = await this.encryptionService.decrypt(passKey, wrappedPrK);\r\n return KFS.asKey(prkJson);\r\n } catch (error) {\r\n throw new LrAuthException('Wrong current password');\r\n }\r\n }\r\n\r\n private async verifyPassword(\r\n password: string,\r\n currentUser: ApiCurrentUser\r\n ): Promise<{ passIdp: JWK.Key; signedChallenge: JWS.CreateSignResult }> {\r\n // Get information from the server to prepare for password change.\r\n const passwordRequest = await this.apollo.mutate<PasswordChangeRequestMutation>(\r\n {\r\n mutation: PasswordChangeRequestMutation,\r\n variables: {},\r\n }\r\n );\r\n\r\n // Get the old passKey so we can decrypt the old password verifier\r\n const passKeyResult = await this.keyFactory.derivePassKey({\r\n password,\r\n ...currentUser.currentUserKey.passKey.passKeyParams,\r\n });\r\n\r\n const verifierPrK = await this.getVerifierPrK(\r\n passKeyResult.jwk,\r\n currentUser.currentUserKey.passKey.wrappedPassIdpVerifierPrk\r\n );\r\n\r\n // Sign the server challenge to prove to the server we can decrypt the password verifier.\r\n // Generate\r\n const clientNonce = this.keyFactory.randomString(this.CLIENT_NONCE_LENGTH);\r\n\r\n const signedChallenge = await this.encryptionService.sign(verifierPrK, {\r\n serverNonce: passwordRequest.passwordChangeRequest.challenge.serverNonce,\r\n clientNonce,\r\n });\r\n\r\n const passIdpResult = await this.keyFactory.derivePassIdp({\r\n password,\r\n ...currentUser.currentUserKey.passKey.passIdpParams,\r\n });\r\n\r\n return {\r\n passIdp: passIdpResult.jwk,\r\n signedChallenge,\r\n };\r\n }\r\n\r\n private async changePasswordMutation(\r\n signedChallenge: JWS.CreateSignResult,\r\n masterKeyId: string,\r\n newWrappedMasterKey: object,\r\n passKeyBundle: PassKeyBundle\r\n ): Promise<{ token: string; newPassKeyId: string }> {\r\n const response = await this.apollo.mutate<PasswordChangeMutation>({\r\n mutation: PasswordChangeMutation,\r\n variables: {\r\n input: {\r\n signedChallenge: JSON.stringify(signedChallenge),\r\n masterKeyId,\r\n newWrappedMasterKey: JSON.stringify(newWrappedMasterKey),\r\n newPassKey: {\r\n passIdpParams: JSON.stringify(passKeyBundle.passIdpParams),\r\n passIdpVerifierPbk: JSON.stringify(\r\n passKeyBundle.passIdpVerifier.toJSON()\r\n ),\r\n wrappedPassIdpVerifierPrk: JSON.stringify(\r\n passKeyBundle.wrappedPassIdpVerifierPrk\r\n ),\r\n passKeyParams: JSON.stringify(passKeyBundle.passKeyParams),\r\n },\r\n },\r\n },\r\n });\r\n return {\r\n token: response.passwordChange.token,\r\n newPassKeyId: response.passwordChange.newPassKey.id,\r\n };\r\n }\r\n\r\n async getChangePasswordConfig(): Promise<PasswordChangeConfig> {\r\n const res = await this.apollo.query<any>({\r\n query: PasswordChangeConfigQuery,\r\n });\r\n\r\n const ret = res.passwordChangeConfig as PasswordChangeConfig;\r\n\r\n ret.authTime = new Date(ret.authTime);\r\n ret.serverTime = new Date(ret.serverTime);\r\n return ret;\r\n }\r\n\r\n public passwordStrength(password): { years: number; bits: number } {\r\n const upper = /[A-Z]/g;\r\n const lower = /[a-z]/g;\r\n const digit = /[0-9]/g;\r\n\r\n const upperChoices = 26;\r\n const lowerChoices = 26;\r\n const digitChoices = 10;\r\n const specialChoices = 30; // /[!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~]/g\r\n\r\n function instanceCount(str, re) {\r\n return ((str || '').match(re) || []).length;\r\n }\r\n\r\n const uppers = instanceCount(password, upper);\r\n const lowers = instanceCount(password, lower);\r\n const digits = instanceCount(password, digit);\r\n const specials = password.length - uppers - lowers - digits;\r\n\r\n let choices = 0;\r\n if (uppers) {\r\n choices += upperChoices;\r\n }\r\n if (lowers) {\r\n choices += lowerChoices;\r\n }\r\n if (digits) {\r\n choices += digitChoices;\r\n }\r\n if (specials) {\r\n choices += specialChoices;\r\n }\r\n\r\n if (password.length === 0) {\r\n return {\r\n years: 0,\r\n // bits of entropy\r\n bits: 0,\r\n };\r\n }\r\n\r\n const permutations = Math.pow(choices, password.length);\r\n\r\n const years =\r\n (54000 * permutations) /\r\n Math.pow(upperChoices + lowerChoices + digitChoices, 12);\r\n return {\r\n years,\r\n // bits of entropy\r\n bits: Math.round(Math.log2(permutations)),\r\n };\r\n }\r\n}\r\n","import { GenericScalar, ID } from '../api/types';\r\nimport { gqlTyped } from '../_common/ast';\r\nimport {\r\n TpClaimState,\r\n TpClaimApproverState,\r\n} from '../api/types/lr-graphql.types';\r\nimport { DateTime } from '../api/types/graphql.types';\r\n\r\nexport interface SharedTpPasswordResetFragmentResult {\r\n id: ID;\r\n tp: {\r\n id: ID;\r\n other: {\r\n username: string;\r\n };\r\n };\r\n assembly: {\r\n asApprovers: {\r\n edges: {\r\n node: {\r\n id: ID;\r\n sharedKey: {\r\n id: ID;\r\n };\r\n sharedCipherData: string;\r\n sharedCipherDataClearJson: any;\r\n };\r\n }[];\r\n };\r\n };\r\n sharedRequest: {\r\n id: ID;\r\n pxk: {\r\n id: ID;\r\n pbk: string;\r\n };\r\n claim: {\r\n id: ID;\r\n state: TpClaimState;\r\n asClaimApprovers: {\r\n edges: {\r\n node: {\r\n id: ID;\r\n state: TpClaimApproverState;\r\n sharedKey: {\r\n id: ID;\r\n };\r\n sharedCipherApprovalData: string;\r\n sharedCipherApprovalDataClearJson: any;\r\n sharedCipherPartialAssemblyKey: string;\r\n sharedCipherPartialAssemblyKeyClearJson: any;\r\n receiverApprovals: {\r\n edges: {\r\n node: {\r\n id: ID;\r\n };\r\n }[];\r\n };\r\n };\r\n }[];\r\n };\r\n };\r\n };\r\n}\r\nconst SharedTpPasswordResetFragment = gqlTyped<SharedTpPasswordResetFragmentResult>`\r\nfragment SharedTpPasswordResetFragment on SharedTpPasswordResetNode {\r\n id\r\n tp {\r\n id\r\n other {\r\n username\r\n }\r\n }\r\n assembly {\r\n asApprovers {\r\n edges {\r\n node {\r\n id\r\n sharedKey {\r\n id\r\n }\r\n sharedCipherData\r\n }\r\n }\r\n }\r\n }\r\n sharedRequest {\r\n id\r\n pxk {\r\n id\r\n pbk\r\n }\r\n claim {\r\n id\r\n state\r\n asClaimApprovers {\r\n edges {\r\n node {\r\n id\r\n state\r\n sharedKey {\r\n id\r\n }\r\n sharedCipherApprovalData\r\n sharedCipherPartialAssemblyKey\r\n receiverApprovals {\r\n edges {\r\n node {\r\n id\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}`;\r\n\r\nexport interface SharedTpPasswordResetsQueryResult {\r\n sharedTpPasswordResets: {\r\n edges: {\r\n node: SharedTpPasswordResetFragmentResult;\r\n }[];\r\n };\r\n}\r\nexport const SharedTpPasswordResetsQuery = gqlTyped<SharedTpPasswordResetsQueryResult>`\r\nquery SharedTpPasswordResetsQuery {\r\n sharedTpPasswordResets {\r\n edges {\r\n node {\r\n ...SharedTpPasswordResetFragment\r\n }\r\n }\r\n }\r\n}\r\n${SharedTpPasswordResetFragment}\r\n`;\r\n\r\nexport interface SharedTpPasswordResetQueryResult {\r\n sharedTpPasswordReset: SharedTpPasswordResetFragmentResult;\r\n}\r\nexport const SharedTpPasswordResetQuery = gqlTyped<SharedTpPasswordResetQueryResult>`\r\nquery SharedTpPasswordResetQuery($id: LrRelayIdInput!) {\r\n sharedTpPasswordReset(id: $id) {\r\n ...SharedTpPasswordResetFragment\r\n }\r\n}\r\n${SharedTpPasswordResetFragment}\r\n`;\r\n\r\nexport interface CancelTpPasswordResetRequestMutationResult {\r\n cancelTpPasswordResetRequest: {\r\n id: ID;\r\n };\r\n}\r\nexport const CancelTpPasswordResetRequestMutation = gqlTyped<CancelTpPasswordResetRequestMutationResult>`\r\nmutation CancelTpPasswordResetRequestMutation {\r\n cancelTpPasswordResetRequest(input: {}) {\r\n id\r\n }\r\n}`;\r\n\r\nexport interface CreateTpAssemblyKeyChallengeMutationResult {\r\n createTpAssemblyKeyChallenge: {\r\n challenge: any;\r\n };\r\n}\r\nexport const CreateTpAssemblyKeyChallengeMutation = gqlTyped<CreateTpAssemblyKeyChallengeMutationResult>`\r\nmutation CreateTpAssemblyKeyChallengeMutation(\r\n $input: CreateTpAssemblyKeyChallengeInput!\r\n) {\r\n createTpAssemblyKeyChallenge(input: $input) {\r\n challenge\r\n }\r\n}`;\r\n\r\nexport interface PreCompleteTpPasswordResetRequestMutationResult {\r\n preCompleteTpPasswordResetRequest: {\r\n idpPassword: string;\r\n };\r\n}\r\nexport const PreCompleteTpPasswordResetRequestMutation = gqlTyped<PreCompleteTpPasswordResetRequestMutationResult>`\r\nmutation PreCompleteTpPasswordResetRequestMutation(\r\n $input: PreCompleteTpPasswordResetRequestInput!\r\n) {\r\n preCompleteTpPasswordResetRequest(input: $input) {\r\n idpPassword\r\n }\r\n}`;\r\n\r\nexport interface CompleteTpPasswordResetRequestMutationResult {\r\n completeTpPasswordResetRequest: {\r\n id: ID;\r\n };\r\n}\r\nexport const CompleteTpPasswordResetRequestMutation = gqlTyped<CompleteTpPasswordResetRequestMutationResult>`\r\nmutation CompleteTpPasswordResetRequestMutation(\r\n $input: CompleteTpPasswordResetRequestInput!\r\n) {\r\n completeTpPasswordResetRequest(input: $input) {\r\n id\r\n }\r\n}`;\r\n\r\nexport interface ApproveTpPasswordResetRequestMutationResult {\r\n approveTpPasswordResetRequest: {\r\n claimApprover: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const ApproveTpPasswordResetRequestMutation = gqlTyped<ApproveTpPasswordResetRequestMutationResult>`\r\nmutation ApproveTpPasswordResetRequestMutation(\r\n $input: ApproveTpPasswordResetRequestInput!\r\n) {\r\n approveTpPasswordResetRequest(input: $input) {\r\n claimApprover {\r\n id\r\n }\r\n }\r\n}`;\r\n\r\nexport interface RejectTpPasswordResetRequestMutationResult {\r\n rejectTpPasswordResetRequest: {\r\n claimApprover: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const RejectTpPasswordResetRequestMutation = gqlTyped<RejectTpPasswordResetRequestMutationResult>`\r\nmutation RejectTpPasswordResetRequestMutation(\r\n $input: RejectTpPasswordResetRequestInput!\r\n) {\r\n rejectTpPasswordResetRequest(input: $input) {\r\n claimApprover {\r\n id\r\n }\r\n }\r\n}`;\r\n\r\nexport interface TpPasswordResetUserQueryResult {\r\n tpPasswordResetUser: {\r\n username: string;\r\n resetUsername: string;\r\n state: TpClaimState;\r\n passKey: {\r\n id: ID;\r\n passKeyParams: GenericScalar;\r\n passIdpParams: GenericScalar;\r\n };\r\n masterKey: {\r\n id: ID;\r\n };\r\n pxk: {\r\n id: ID;\r\n };\r\n sessionEncryptionKey: string;\r\n assembly: {\r\n singleReject: boolean;\r\n quorum: number;\r\n subAssemblies: {\r\n singleReject: boolean;\r\n quorum: number;\r\n approvers: {\r\n name: string;\r\n email: string;\r\n state: TpClaimApproverState;\r\n }[];\r\n }[];\r\n };\r\n approvals: {\r\n id: ID;\r\n modified: DateTime;\r\n approverEmail: string;\r\n receiverCipher: string;\r\n receiverCipherPartialAssemblyKey: string;\r\n }[];\r\n assemblyCipherData: string;\r\n wrappedAssemblyKeyVerifierPrk: string;\r\n };\r\n}\r\nexport const TpPasswordResetUserQuery = gqlTyped<TpPasswordResetUserQueryResult>`\r\nquery TpPasswordResetUserQuery {\r\n tpPasswordResetUser {\r\n username\r\n resetUsername\r\n state\r\n passKey {\r\n id\r\n passKeyParams\r\n passIdpParams\r\n }\r\n masterKey {\r\n id\r\n }\r\n pxk {\r\n id\r\n }\r\n sessionEncryptionKey\r\n assembly {\r\n singleReject\r\n quorum\r\n subAssemblies {\r\n singleReject\r\n quorum\r\n approvers {\r\n name\r\n email\r\n state\r\n }\r\n }\r\n }\r\n approvals {\r\n id\r\n modified\r\n approverEmail\r\n receiverCipher\r\n receiverCipherPartialAssemblyKey\r\n }\r\n assemblyCipherData\r\n wrappedAssemblyKeyVerifierPrk\r\n }\r\n}`;\r\n\r\nexport interface TpPasswordResetQueryResult {\r\n tpPasswordReset: {\r\n id: ID;\r\n applied: boolean;\r\n assembly: {\r\n singleReject: boolean;\r\n quorum: number;\r\n subjectKey: {\r\n id: ID;\r\n };\r\n assemblyKey: {\r\n id: ID;\r\n };\r\n assemblyCipherData: string;\r\n subAssemblies: {\r\n edges: {\r\n node: {\r\n id: ID;\r\n singleReject: boolean;\r\n quorum: number;\r\n subjectCipherData: string;\r\n subjectCipherDataClearJson: any;\r\n approvers: {\r\n edges: {\r\n node: {\r\n id: ID;\r\n tp: {\r\n id: ID;\r\n };\r\n sharedKey: {\r\n id: ID;\r\n };\r\n sharedCipherData: string;\r\n };\r\n }[];\r\n };\r\n };\r\n }[];\r\n };\r\n };\r\n };\r\n}\r\nexport const TpPasswordResetQuery = gqlTyped<TpPasswordResetQueryResult>`\r\nquery TpPasswordResetQuery {\r\n tpPasswordReset {\r\n id\r\n applied\r\n assembly {\r\n singleReject\r\n quorum\r\n subjectKey {\r\n id\r\n }\r\n assemblyKey {\r\n id\r\n }\r\n assemblyCipherData\r\n subAssemblies {\r\n edges {\r\n node {\r\n id\r\n singleReject\r\n quorum\r\n subjectCipherData\r\n approvers {\r\n edges {\r\n node {\r\n id\r\n tp {\r\n id\r\n }\r\n sharedKey {\r\n id\r\n }\r\n sharedCipherData\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}`;\r\n\r\nexport interface CreateTpPasswordResetMutationResult {\r\n createTpPasswordReset: {\r\n tpPasswordReset: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const CreateTpPasswordResetMutation = gqlTyped<CreateTpPasswordResetMutationResult>`\r\nmutation CreateTpPasswordResetMutation($input: CreateTpPasswordResetInput!) {\r\n createTpPasswordReset(input: $input) {\r\n tpPasswordReset {\r\n id\r\n }\r\n }\r\n}`;\r\n\r\nexport interface DeleteTpPasswordResetMutationResult {\r\n deleteTpPasswordReset: {\r\n id: ID;\r\n };\r\n}\r\nexport const DeleteTpPasswordResetMutation = gqlTyped<DeleteTpPasswordResetMutationResult>`\r\nmutation DeleteTpPasswordResetMutation {\r\n deleteTpPasswordReset(input: {}) {\r\n id\r\n }\r\n}`;\r\n\r\nexport interface UpdateTpPasswordResetMutationResult {\r\n updateTpPasswordReset: {\r\n tpPasswordReset: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const UpdateTpPasswordResetMutation = gqlTyped<UpdateTpPasswordResetMutationResult>`\r\nmutation UpdateTpPasswordResetMutation($input: UpdateTpPasswordResetInput!) {\r\n updateTpPasswordReset(input: $input) {\r\n tpPasswordReset {\r\n id\r\n }\r\n }\r\n}`;\r\n","// Promise.all always returns a promise, even if all the values are not async.\r\n// During processing of deep hierarchies of nested objects we don't always need to\r\n\r\n// promote everything to a promise.\r\nexport function promiseAllMayAsync(values: any[]): Promise<any> | any {\r\n if (!Array.isArray(values)) {\r\n throw new Error('not array');\r\n }\r\n if (values.some((value) => value?.then)) {\r\n const ret = Promise.all(values);\r\n return ret;\r\n } else {\r\n return values;\r\n }\r\n}\r\n\r\nfunction remap(obj, values) {\r\n const ret = {};\r\n for (const [i, key] of Object.keys(obj).entries()) {\r\n ret[key] = values[i];\r\n }\r\n return ret;\r\n}\r\n\r\nexport function mapValuesMayAsync(\r\n obj: object,\r\n // callback can either return a Promise, or a value.\r\n // The Promise<any> type is redundant but it shows that it can return a promise\r\n callback: (value: any, key: string, obj: object) => any | Promise<any>\r\n): Promise<any> | any {\r\n const values = promiseAllMayAsync(\r\n Object.entries(obj).map(([key, value]) => callback(value, key, obj))\r\n );\r\n\r\n if (values.then) {\r\n return values.then((resolvedValues) => remap(obj, resolvedValues));\r\n } else {\r\n return remap(obj, values);\r\n }\r\n}\r\n\r\nexport function mapValuesAsync(\r\n obj: object,\r\n // callback can either return a Promise, or a value.\r\n // The Promise<any> type is redundant but it shows that it can return a promise\r\n // By default, it returns the value without any process, so you can use\r\n // this to simply wait for all promises in an object to resolve.\r\n callback?: (value: any, key: string, obj: object) => any | Promise<any>\r\n): Promise<any> {\r\n const values = Promise.all(\r\n Object.entries(obj).map(([key, value]) =>\r\n callback ? callback(value, key, obj) : value\r\n )\r\n );\r\n\r\n return values.then((resolvedValues) => remap(obj, resolvedValues));\r\n}\r\n","import { LrBadLogicException } from '../_common/exceptions';\r\n\r\nexport interface RunOutsideAngularConfig {\r\n ngZoneName: string;\r\n // If true, a single change detection is triggered on resolve of the Promise returned\r\n // from the function.\r\n // else, the entire function is run outside of zone.\r\n // Note that if this is disabled, then change detection is not triggered even if you\r\n // use async pipes to subscribe to observables on the resulting promise. This is because\r\n // async pipes only _marks_ a component for change detection, it doesn't actually _trigger_\r\n // the change detection cycle.\r\n exceptLastPromise?: boolean;\r\n // Any method or property you wish to exclude from patch. The methods in EXCLUDE_METHODS are\r\n // never patched.\r\n excludeMethods?: string[];\r\n // If true, patch the setters as well. Settings are some\r\n // Note that setters do not return any thing. But they can still issue async calls.\r\n // These async calls are not visible to the wrapper. So we can't issue change detection\r\n // for setters when they are running outside angular.\r\n // Note that getters are not patched because getter and setter must use the same type. So if\r\n // the getter returns a promise, then the setting must alway take a promise. It doesn't make\r\n // much sense to use getters and setters this way. And if getter returns a value, then there's\r\n // no need to patch it to run outside angular.\r\n patchSetters?: boolean;\r\n}\r\n\r\n/**\r\n * If you wish to change the behaviour of those, you'll need to create a derived\r\n * class and override the methods.\r\n * However, can't figure out a way to call the super() in the derived class ctor, error says\r\n * the super call can't be in tested function.\r\n */\r\nexport const EXCLUDE_METHODS = [\r\n 'constructor',\r\n 'ngOnChanges',\r\n 'ngOnInit',\r\n 'ngDoCheck',\r\n 'ngAfterContentInit',\r\n 'ngAfterContentChecked',\r\n 'ngAfterViewInit',\r\n 'ngAfterViewChecked',\r\n 'ngOnDestroy',\r\n];\r\n\r\n// Patch all methods of the class.\r\n//\r\n// Note, this will not patch functions in the base class, it only\r\n// patches the function defined in the current class because it's\r\n// using getOwnPropertyNames(). You should be using composition for\r\n// services anyway.\r\n//\r\n// Ref: https://stackoverflow.com/a/44409244\r\n// The above approach might be a bit old. Now that we have ngZone.runOutsideAngular(),\r\n// we should probably use that and not touch any angular zone internals. But the approach\r\n// above doesn't require injecting ngZone.\r\n//\r\n// Ref: https://github.com/2ng/run-outside-angular/blob/master/src/run-outside-angular.ts\r\nexport function RunOutsideAngular({\r\n ngZoneName,\r\n exceptLastPromise = true,\r\n excludeMethods = [],\r\n patchSetters = true,\r\n}: RunOutsideAngularConfig) {\r\n return (target: any) => {\r\n function run(original, args) {\r\n if (!this[ngZoneName]) {\r\n throw new LrBadLogicException(\r\n `RunOutsideAngular decorator requires that ${target.name} inject NgZone as ${ngZoneName}`\r\n );\r\n }\r\n // runOutsideAngular() synchronously runs the callback and returns the result.\r\n const result = this[ngZoneName].runOutsideAngular(() =>\r\n original.apply(this, args)\r\n );\r\n\r\n if (exceptLastPromise && result?.then) {\r\n // Bring back into zone which will trigger change detection properly.\r\n // If this doesn't work, then we'll have to trigger change detection explicitly.\r\n return Promise.resolve(result);\r\n } else {\r\n return result;\r\n }\r\n }\r\n\r\n // There should be no reason to run any of the ones in EXCLUDE_METHODS outside angular.\r\n // So we always exclude them from patching. You can always explicit implement these ones differently.\r\n excludeMethods = [...excludeMethods, ...EXCLUDE_METHODS];\r\n\r\n const methods = Object.getOwnPropertyNames(target.prototype);\r\n\r\n methods\r\n .filter((method) => !excludeMethods.includes(method))\r\n .forEach((method) => {\r\n // Patch setters\r\n // Note that setters do not return any thing. But they can still issue async calls.\r\n // These async calls are not visible to the wrapper. So we can't issue change detection\r\n // for setters when they are running outside angular.\r\n if (\r\n patchSetters &&\r\n Object.getOwnPropertyDescriptor(target.prototype, method).set\r\n ) {\r\n const original = Object.getOwnPropertyDescriptor(\r\n target.prototype,\r\n method\r\n ).set;\r\n\r\n Object.defineProperty(target.prototype, method, {\r\n set(...args) {\r\n return run.apply(this, [original, args]);\r\n },\r\n });\r\n }\r\n\r\n if (typeof target.prototype[method] === 'function') {\r\n const original = target.prototype[method];\r\n\r\n target.prototype[method] = function(...args) {\r\n return run.apply(this, [original, args]);\r\n };\r\n }\r\n });\r\n\r\n return target;\r\n };\r\n}\r\n","import { Injectable, NgZone } from '@angular/core';\r\nimport { EncryptionService } from '../../cryptography/encryption.service';\r\nimport { KeyGraphService } from '../../cryptography/key-graph.service';\r\nimport { LrBadLogicException } from '../../_common/exceptions';\r\nimport { RunOutsideAngular } from '../../_common/run-outside-angular';\r\nimport { Connection } from '../types';\r\n\r\nexport interface ProcessorOptions {\r\n hasKeys: boolean;\r\n}\r\n\r\nexport const DefaultProcessorOptions: ProcessorOptions = {\r\n hasKeys: true,\r\n};\r\n\r\n// Sent to each processor for context information\r\nexport interface ProcessorContext {\r\n path: ReadonlyArray<string>;\r\n // processor can set this to false if child fields should\r\n // not be processed any further\r\n processChildren: boolean;\r\n}\r\n\r\nexport interface ProcessorCallbackParams<T = any> {\r\n field: T;\r\n context: ProcessorContext;\r\n options: ProcessorOptions;\r\n}\r\n\r\nexport type ProcessorCallback<T = any> = (\r\n params: ProcessorCallbackParams<T>\r\n) => T | Promise<T>;\r\n\r\ninterface ParseJsonProcessorOptions {\r\n plainFieldName?: string;\r\n jsonFieldSuffix?: string;\r\n}\r\n\r\ninterface DecryptionProcessorOptions {\r\n cipherFieldName?: string;\r\n clearFieldSuffix?: string;\r\n getKeyId?: (params: ProcessorCallbackParams) => Promise<string> | string;\r\n}\r\n\r\nexport async function processConnection<Node>(\r\n field: Connection<Node>,\r\n processNode: (node: Node) => Node | Promise<Node>\r\n): Promise<Connection<Node>> {\r\n return {\r\n ...field,\r\n edges: await Promise.all(\r\n field.edges.map(async (edge) => ({\r\n ...edge,\r\n node: await processNode(edge.node),\r\n }))\r\n ),\r\n };\r\n}\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class CommonProcessorsService {\r\n constructor(private ngZone: NgZone, private keyGraph: KeyGraphService) {}\r\n\r\n series(processors: ProcessorCallback[]): ProcessorCallback {\r\n return async ({ field, context, options }) => {\r\n for (const processor of processors) {\r\n field = await processor({ field, context, options });\r\n }\r\n return field;\r\n };\r\n }\r\n\r\n makeJsonParseProcessor({\r\n plainFieldName,\r\n jsonFieldSuffix = 'Json',\r\n }: ParseJsonProcessorOptions = {}): ProcessorCallback {\r\n const jsonFieldName = plainFieldName + jsonFieldSuffix;\r\n\r\n return ({ field }) => {\r\n if (field[plainFieldName] == null || jsonFieldName in field) {\r\n // if plainFieldName is undefined or null, then don't parse it.\r\n // if you parse it, then JSON.parse(null) and JSON.parse(\"null\") both return null, so\r\n // you can't distinguish between the two.\r\n // If clearFieldName already exists in node as a property, then we don't\r\n // need to process it again, even if it's value can be undefined or null even.\r\n return field;\r\n }\r\n\r\n try {\r\n return {\r\n ...field,\r\n [jsonFieldName]: JSON.parse(field[plainFieldName]),\r\n };\r\n } catch (error) {\r\n return field;\r\n }\r\n };\r\n }\r\n\r\n makeDecryptionProcessor({\r\n cipherFieldName,\r\n clearFieldSuffix = 'ClearJson',\r\n getKeyId = null,\r\n }: DecryptionProcessorOptions = {}): ProcessorCallback {\r\n const clearFieldName = cipherFieldName + clearFieldSuffix;\r\n\r\n return async (params) => {\r\n const { field, context, options } = params;\r\n\r\n // Can't decrypt anything if key graph is not returned\r\n if (!options.hasKeys) {\r\n return field;\r\n }\r\n\r\n const cipherField = field[cipherFieldName];\r\n\r\n // cipherField can be empty string, null or undefined.\r\n if (!cipherField || clearFieldName in field) {\r\n return field;\r\n }\r\n\r\n const keyId = getKeyId\r\n ? await getKeyId(params)\r\n : field.keyId || field.key?.id;\r\n\r\n if (!keyId) {\r\n const keyIdName = getKeyId ? 'key-id' : 'keyId or key.id';\r\n throw new LrBadLogicException(\r\n `Query response does not contain ${keyIdName} field: ${context.path.join(\r\n '.'\r\n )}`\r\n );\r\n }\r\n\r\n return this.keyGraph\r\n .decryptFromString(keyId, cipherField)\r\n .then((clear) => ({\r\n ...field,\r\n [clearFieldName]: clear,\r\n }));\r\n };\r\n }\r\n}\r\n","import { Injectable, NgZone } from '@angular/core';\r\nimport { KeyGraphService } from '../../cryptography/key-graph.service';\r\nimport { RunOutsideAngular } from '../../_common/run-outside-angular';\r\nimport {\r\n ID,\r\n SharedTpAssemblyNode,\r\n TpAssemblyApproverNode,\r\n TpAssemblyNode,\r\n TpSubAssemblyNode,\r\n} from '../types';\r\nimport {\r\n processConnection,\r\n ProcessorCallbackParams,\r\n} from './common-processors.service';\r\nimport {\r\n TpPasswordResetUserNode,\r\n TpPasswordResetUserApprovalNode,\r\n TpPasswordResetNode,\r\n} from '../types';\r\nimport { Key } from '../../cryptography/cryptography.types';\r\nimport { LrBadRequestException } from '../../_common/exceptions';\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class TpPasswordResetProcessorService {\r\n constructor(private ngZone: NgZone, private keyGraph: KeyGraphService) {}\r\n\r\n async processTpPasswordResetUserNode(\r\n node: TpPasswordResetUserNode\r\n ): Promise<TpPasswordResetUserNode> {\r\n const pxk = node.pxk?.id && (await this.keyGraph.getKey(node.pxk.id));\r\n\r\n const ret = {\r\n ...node,\r\n };\r\n\r\n if (pxk && node.approvals) {\r\n ret.approvals = await Promise.all(\r\n node.approvals.map((approval) =>\r\n this.processTpPasswordResetUserApprovalNode(approval, pxk)\r\n )\r\n );\r\n }\r\n\r\n return ret;\r\n }\r\n\r\n private async processTpPasswordResetUserApprovalNode(\r\n approval: TpPasswordResetUserApprovalNode,\r\n pxk: Key\r\n ) {\r\n const ret = {\r\n ...approval,\r\n };\r\n\r\n if (approval.receiverCipher) {\r\n ret.receiverCipherClearJson = this.keyGraph.decryptFromString(\r\n pxk,\r\n approval.receiverCipher\r\n );\r\n }\r\n\r\n if (approval.receiverCipherPartialAssemblyKey) {\r\n ret.receiverCipherPartialAssemblyKeyClearJson = this.keyGraph.decryptFromString(\r\n pxk,\r\n approval.receiverCipherPartialAssemblyKey\r\n );\r\n }\r\n return ret;\r\n }\r\n\r\n makeTpPasswordResetNodeProcessor() {\r\n return async ({\r\n field,\r\n }: ProcessorCallbackParams): Promise<TpPasswordResetNode> => {\r\n const ret = {\r\n ...field,\r\n };\r\n\r\n if (field.assembly) {\r\n if (field.applied == null) {\r\n throw new LrBadRequestException(\r\n 'If you request for field \"assembly\" in the TpPasswordResetNode, then you must also request the \"applied\" field'\r\n );\r\n }\r\n\r\n ret.assembly = await this.processTpAssemblyNode(\r\n field.assembly,\r\n field.applied\r\n );\r\n }\r\n\r\n return ret;\r\n };\r\n }\r\n\r\n private async processTpAssemblyNode(\r\n assembly: TpAssemblyNode,\r\n applied: boolean\r\n ): Promise<TpAssemblyNode> {\r\n // Subject key is encrypted user the master key. So if reset has been applied, then\r\n // these keys are not available any more.\r\n const {\r\n subjectKey,\r\n assemblyKey,\r\n assemblyCipherData,\r\n subAssemblies,\r\n } = assembly;\r\n\r\n const ret: TpAssemblyNode = {\r\n ...assembly,\r\n subAssemblies: await processConnection(subAssemblies, (node) =>\r\n this.processTpSubAssemblyNode(node, subjectKey.id, applied)\r\n ),\r\n };\r\n\r\n if (!applied) {\r\n if (assemblyCipherData) {\r\n ret.assemblyCipherDataClearJson = await this.keyGraph.decryptFromString(\r\n assemblyKey.id,\r\n assemblyCipherData\r\n );\r\n }\r\n }\r\n\r\n return ret;\r\n }\r\n\r\n private async processTpSubAssemblyNode(\r\n subAssembly: TpSubAssemblyNode,\r\n subjectKeyId: ID,\r\n applied: boolean\r\n ): Promise<TpSubAssemblyNode> {\r\n const { subjectCipherData, approvers } = subAssembly;\r\n\r\n // const ret: TpSubAssemblyNode = {\r\n // ...subAssembly,\r\n // approvers: {\r\n // ...approvers,\r\n // edges: await Promise.all(\r\n // approvers.edges.map(async (edge) => ({\r\n // ...edge,\r\n // node: await this.processTpAssemblyApproverNode(edge.node, applied),\r\n // }))\r\n // ),\r\n // },\r\n // };\r\n const ret: TpSubAssemblyNode = {\r\n ...subAssembly,\r\n approvers: await processConnection(approvers, (node) =>\r\n this.processTpAssemblyApproverNode(node, applied)\r\n ),\r\n };\r\n\r\n if (!applied) {\r\n if (subjectCipherData) {\r\n ret.subjectCipherDataClearJson = await this.keyGraph.decryptFromString(\r\n subjectKeyId,\r\n subjectCipherData\r\n );\r\n }\r\n }\r\n\r\n return ret;\r\n }\r\n\r\n private async processTpAssemblyApproverNode(\r\n approver: TpAssemblyApproverNode,\r\n applied: boolean\r\n ) {\r\n return approver;\r\n }\r\n}\r\n","import { Injectable, NgZone } from '@angular/core';\r\nimport { LrBadLogicException } from '../../_common/exceptions';\r\nimport { mapValuesMayAsync, promiseAllMayAsync } from '../../_common/utils';\r\nimport { KeyService } from '../../cryptography/key.service';\r\nimport {\r\n CommonProcessorsService,\r\n // FieldContext,\r\n ProcessorCallback,\r\n ProcessorCallbackParams,\r\n ProcessorContext,\r\n ProcessorOptions,\r\n DefaultProcessorOptions,\r\n} from './common-processors.service';\r\nimport { TpPasswordResetService } from '../../trusted-parties/tp-password-reset.service';\r\nimport { RunOutsideAngular } from '../../_common/run-outside-angular';\r\nimport { TpPasswordResetProcessorService } from './tp-password-reset-processor.service';\r\n\r\nfunction extendPath(context: ProcessorContext, key: string): ProcessorContext {\r\n return {\r\n ...context,\r\n path: [...context.path, key],\r\n };\r\n}\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class QueryProcessorService {\r\n readonly TYPENAME = '__typename';\r\n private processors: { [key: string]: ProcessorCallback } = {};\r\n\r\n constructor(\r\n private ngZone: NgZone,\r\n private keyService: KeyService,\r\n private common: CommonProcessorsService,\r\n private tpprProcessor: TpPasswordResetProcessorService\r\n ) {\r\n this.registerProcessor(\r\n 'DirectoryNode',\r\n common.series([\r\n common.makeJsonParseProcessor({\r\n plainFieldName: 'plainMeta',\r\n }),\r\n common.makeDecryptionProcessor({\r\n cipherFieldName: 'cipherMeta',\r\n }),\r\n ])\r\n );\r\n this.registerProcessor(\r\n 'FileStateNode',\r\n common.series([\r\n common.makeJsonParseProcessor({\r\n plainFieldName: 'plainMeta',\r\n }),\r\n common.makeDecryptionProcessor({\r\n cipherFieldName: 'cipherMeta',\r\n }),\r\n ])\r\n );\r\n this.registerProcessor(\r\n 'ContactCardNode',\r\n common.makeDecryptionProcessor({\r\n cipherFieldName: 'cipherData',\r\n })\r\n );\r\n this.registerProcessor(\r\n 'SharedContactCardNode',\r\n common.series([\r\n common.makeJsonParseProcessor({\r\n plainFieldName: 'ownerPlainData',\r\n }),\r\n common.makeDecryptionProcessor({\r\n cipherFieldName: 'ownerCipherData',\r\n getKeyId: ({ field }) => {\r\n return field.ownerKey.id;\r\n },\r\n }),\r\n common.makeDecryptionProcessor({\r\n cipherFieldName: 'receiverCipherData',\r\n getKeyId: ({ field }) => {\r\n return field.receiverKey.id;\r\n },\r\n }),\r\n common.makeDecryptionProcessor({\r\n cipherFieldName: 'sharedCipherData',\r\n getKeyId: ({ field }) => field.sharedKey.id,\r\n }),\r\n ])\r\n );\r\n this.registerProcessor(\r\n 'TpPasswordResetNode',\r\n this.tpprProcessor.makeTpPasswordResetNodeProcessor()\r\n );\r\n this.registerProcessor(\r\n 'SharedTpClaimApproverNode',\r\n common.series([\r\n common.makeDecryptionProcessor({\r\n cipherFieldName: 'sharedCipherApprovalData',\r\n getKeyId: ({ field }) => field.sharedKey.id,\r\n }),\r\n common.makeDecryptionProcessor({\r\n cipherFieldName: 'sharedCipherPartialAssemblyKey',\r\n getKeyId: ({ field }) => field.sharedKey.id,\r\n }),\r\n ])\r\n );\r\n this.registerProcessor(\r\n 'TpAssemblyAsApproverNode',\r\n common.series([\r\n common.makeDecryptionProcessor({\r\n cipherFieldName: 'sharedCipherData',\r\n getKeyId: ({ field }) => field.sharedKey.id,\r\n }),\r\n ])\r\n );\r\n }\r\n\r\n async processQuery(\r\n fields: { [key: string]: any },\r\n options: ProcessorOptions\r\n ) {\r\n options = {\r\n ...DefaultProcessorOptions,\r\n ...options,\r\n };\r\n\r\n // The top level query does not have __typename\r\n const ret = mapValuesMayAsync(fields, (field, key) =>\r\n this.processField({\r\n field,\r\n context: {\r\n path: [key],\r\n processChildren: true,\r\n },\r\n options,\r\n })\r\n );\r\n return ret;\r\n }\r\n\r\n // Either returns a Promise, or a value.\r\n // The Promise<any> type is redundant but it shows that it can return a promise\r\n // We are not using async on the function because we don't want auto promotion into a Promise, which\r\n // always defer execution into the event loops. It is costly and unnecessary for objects\r\n // with only native data types.\r\n private async processField({\r\n field,\r\n context,\r\n options,\r\n }: ProcessorCallbackParams) {\r\n if (field?.then) {\r\n throw new LrBadLogicException(\r\n 'processField() should not receive thenable.'\r\n );\r\n }\r\n\r\n if (field == null) {\r\n return null;\r\n }\r\n\r\n const newParams: ProcessorCallbackParams = {\r\n field,\r\n context: {\r\n ...context,\r\n // Processors modifies this field to communicate back to the caller.\r\n processChildren: true,\r\n },\r\n options,\r\n };\r\n\r\n // TODO allow registering processors by field name so we can process primitive fields as well.\r\n // We have common fields like \"created\", \"modified\" that be processed based on name.\r\n if (field[this.TYPENAME]) {\r\n // It's a custom object type\r\n const processor = this.processors[field[this.TYPENAME]];\r\n if (processor) {\r\n // Returns either a value or a promise.\r\n field = processor(newParams);\r\n }\r\n\r\n const processChildren = (childField) => {\r\n if (\r\n context.processChildren &&\r\n childField !== null &&\r\n typeof childField === 'object'\r\n ) {\r\n return mapValuesMayAsync(childField, (x, key) =>\r\n this.processField({\r\n field: x,\r\n context: extendPath(context, key),\r\n options,\r\n })\r\n );\r\n } else {\r\n return childField;\r\n }\r\n };\r\n\r\n // Keep processing all child fields\r\n if (field.then) {\r\n // Wait for field to resolve\r\n field = field.then((resolvedField) => {\r\n return processChildren(resolvedField);\r\n });\r\n } else {\r\n // Field is already resolved\r\n field = processChildren(field);\r\n }\r\n } else {\r\n // Keep processing all child fields\r\n if (context.processChildren) {\r\n if (Array.isArray(field)) {\r\n field = promiseAllMayAsync(\r\n (field as Array<any>).map((x, i) =>\r\n this.processField({\r\n field: x,\r\n context: extendPath(context, i.toString()),\r\n options,\r\n })\r\n )\r\n );\r\n }\r\n }\r\n }\r\n\r\n return field;\r\n }\r\n\r\n private registerProcessor(name: string, processor: ProcessorCallback) {\r\n if (this.processors[name]) {\r\n throw new LrBadLogicException(\r\n `Processor for field ${name} already exists.`\r\n );\r\n }\r\n this.processors[name] = processor;\r\n }\r\n}\r\n","export type ResolvePromise<T> = (value?: T | PromiseLike<T>) => void;\r\nexport type RejectPromise = (reason?: any) => void;\r\n\r\nexport class DeferredPromise<T> {\r\n public readonly promise: Promise<T>;\r\n /* tslint:disable: variable-name */\r\n private _resolve: ResolvePromise<T>;\r\n /* tslint:disable: variable-name */\r\n private _reject: RejectPromise;\r\n /* tslint:disable: variable-name */\r\n private _fulfilled = false;\r\n\r\n constructor() {\r\n this.promise = new Promise<T>((resolve, reject) => {\r\n this._resolve = resolve;\r\n this._reject = reject;\r\n }).finally(() => {\r\n // finally() simply gets called on both then() and catch(). The promise\r\n // chain continues on.\r\n this._fulfilled = true;\r\n });\r\n }\r\n\r\n get resolve() {\r\n return this._resolve;\r\n }\r\n\r\n get reject() {\r\n return this._reject;\r\n }\r\n\r\n get fulfilled() {\r\n return this._fulfilled;\r\n }\r\n}\r\n","import { OperationVariables } from '@apollo/client/core';\r\nimport { FragmentSpreadNode } from 'graphql';\r\nimport gql from 'graphql-tag';\r\nimport { getQuery, TypedDocumentNode } from '../../_common/ast';\r\nimport { DeferredPromise } from '../../_common/deferred-promise';\r\nimport { LrBadStateException } from '../../_common/exceptions';\r\n\r\nexport interface LrMutationData<T, TVariables = OperationVariables> {\r\n mutation: TypedDocumentNode<T>;\r\n variables?: TVariables;\r\n}\r\n\r\nexport const fragmentSpreadAstSelection = getQuery(gql`\r\n query {\r\n ...FragmentName\r\n }\r\n`).selectionSet.selections[0] as FragmentSpreadNode;\r\n\r\n// const fragmentSpreadAstSelection = () =>\r\n// lodash.deepClone(_fragmentSpreadAstSelection) as FragmentSpreadNode;\r\n\r\n/**\r\n * DECISION: LrMutationBase does not provide a convenience method to call lrGraphQL.lrMutate()\r\n * because this class could be made independent of what lib is used to call the API. If we\r\n * provided a configurable call back to make the API call, then the typing for that callback\r\n * needs to be known. But since the API lib (eg. Apollo) has it's own unique return type, so\r\n * it's not possible to do in general.\r\n */\r\nexport abstract class LrMutationBase<T, TVariables = OperationVariables> {\r\n protected mutation: TypedDocumentNode<T>;\r\n protected variables?: TVariables;\r\n /* tslint:disable:variable-name */\r\n protected _executed = false;\r\n\r\n // protected promises: DeferredPromise<T>[] = [];\r\n public readonly deferredPromise = new DeferredPromise<T>();\r\n\r\n get promise(): Promise<T> {\r\n return this.deferredPromise.promise;\r\n }\r\n\r\n resolve(value: T) {\r\n this.deferredPromise.resolve(value);\r\n }\r\n\r\n reject(reason?: any) {\r\n this.deferredPromise.reject(reason);\r\n }\r\n\r\n get lrMutationData(): LrMutationData<T, TVariables> {\r\n return {\r\n mutation: this.mutation,\r\n variables: this.variables,\r\n };\r\n }\r\n\r\n get executed() {\r\n return this._executed;\r\n }\r\n\r\n setExecuted() {\r\n if (this._executed) {\r\n throw new LrBadStateException('Already executed');\r\n }\r\n this._executed = true;\r\n }\r\n}\r\n","import * as lodash from 'lodash';\r\nimport { OperationVariables } from '@apollo/client/core';\r\nimport { DocumentNode, FieldNode, FragmentDefinitionNode } from 'graphql';\r\nimport {\r\n getAliasOrName,\r\n getFragments,\r\n getMutation,\r\n TypedDocumentNode,\r\n} from '../../_common/ast';\r\nimport * as ast from '../../_common/ast';\r\nimport { LrMutationData } from './lr-mutation-base';\r\nimport { fragmentSpreadAstSelection, LrMutationBase } from './lr-mutation-base';\r\n\r\nexport class LrMutation<\r\n T extends any,\r\n TVariables = OperationVariables\r\n> extends LrMutationBase<T, TVariables> {\r\n constructor(options: LrMutationData<T, TVariables>) {\r\n super();\r\n this.mutation = options.mutation;\r\n this.variables = options.variables;\r\n }\r\n\r\n select<TResult>(fragments: TypedDocumentNode<TResult>) {\r\n // Don't touch the original\r\n const mutationDoc = lodash.cloneDeep(this.mutation) as DocumentNode;\r\n const mutationNode = getMutation(mutationDoc);\r\n\r\n const fragmentMap = {} as { [key: string]: FragmentDefinitionNode };\r\n getFragments(fragments).forEach((fragment: FragmentDefinitionNode) => {\r\n fragmentMap[fragment.name.value] = fragment;\r\n });\r\n\r\n const replaceFieldSelection = (selection: FieldNode) => {\r\n const field = selection as FieldNode;\r\n const fieldName = getAliasOrName(field);\r\n const fragment = fragmentMap[fieldName];\r\n\r\n if (!fragment) {\r\n return;\r\n }\r\n\r\n // Make the entire selection of the mutation a spread of\r\n // a fragment using the same name as the mutation field.\r\n // We will also rename the fragment to the same name.\r\n field.selectionSet.selections = [\r\n {\r\n ...fragmentSpreadAstSelection,\r\n name: ast.name(fieldName),\r\n },\r\n ];\r\n };\r\n\r\n mutationNode.selectionSet.selections.forEach((selection) => {\r\n if (selection.kind === 'Field') {\r\n replaceFieldSelection(selection);\r\n }\r\n });\r\n\r\n return new LrMutation({\r\n mutation: {\r\n ...mutationDoc,\r\n definitions: [\r\n // Remove all existing fragments\r\n ...mutationDoc.definitions.filter(\r\n (def) => def.kind !== 'FragmentDefinition'\r\n ),\r\n ...fragments.definitions,\r\n ],\r\n } as TypedDocumentNode<TResult>,\r\n variables: this.variables,\r\n });\r\n }\r\n}\r\n","import {\r\n ArgumentNode,\r\n DocumentNode,\r\n FieldNode,\r\n FragmentDefinitionNode,\r\n FragmentSpreadNode,\r\n SelectionNode,\r\n SelectionSetNode,\r\n VariableDefinitionNode,\r\n} from 'graphql';\r\nimport {\r\n LrBadArgumentException,\r\n LrBadLogicException,\r\n LrUnsupportedException,\r\n} from '../../_common/exceptions';\r\nimport { LrMutation } from './lr-mutation';\r\nimport { LrMutationBase } from './lr-mutation-base';\r\nimport { getAliasOrName, getFragments, getMutation } from '../../_common/ast';\r\nimport * as ast from '../../_common/ast';\r\nimport * as lodash from 'lodash';\r\n\r\nconst lrMergedMutationDoc: DocumentNode = {\r\n kind: 'Document',\r\n definitions: [\r\n {\r\n kind: 'OperationDefinition',\r\n operation: 'mutation',\r\n name: {\r\n kind: 'Name',\r\n value: 'lrMergedMutation',\r\n },\r\n variableDefinitions: [],\r\n directives: [],\r\n selectionSet: {\r\n kind: 'SelectionSet',\r\n selections: [],\r\n },\r\n },\r\n ],\r\n // TODO What to do about these? Serialise and reparse?\r\n // \"loc\": {\r\n // \"start\": 0,\r\n // \"end\": 204\r\n // }\r\n};\r\n\r\nexport class LrMergedMutation<T> extends LrMutationBase<T> {\r\n public readonly descendants: Set<LrMutationBase<any>>;\r\n protected prefixes: string[];\r\n\r\n constructor(public readonly lrMutations: LrMutationBase<any>[]) {\r\n super();\r\n\r\n const { mutation, variables, prefixes } = this.merge();\r\n this.mutation = mutation;\r\n this.variables = variables;\r\n this.prefixes = prefixes;\r\n this.descendants = this.getDescendants();\r\n }\r\n\r\n static create<T1, T2>(\r\n lrMutations: [\r\n LrMutationBase<T1> | LrMergedMutation<T1>,\r\n LrMutationBase<T2> | LrMergedMutation<T2>\r\n ]\r\n ): LrMergedMutation<[T1, T2]>;\r\n\r\n static create<T1, T2, T3>(\r\n lrMutations: [\r\n LrMutationBase<T1> | LrMergedMutation<T1>,\r\n LrMutationBase<T2> | LrMergedMutation<T2>,\r\n LrMutationBase<T3> | LrMergedMutation<T3>\r\n ]\r\n ): LrMergedMutation<[T1, T2, T3]>;\r\n\r\n static create<T1, T2, T3, T4>(\r\n lrMutations: [\r\n LrMutationBase<T1> | LrMergedMutation<T1>,\r\n LrMutationBase<T2> | LrMergedMutation<T2>,\r\n LrMutationBase<T3> | LrMergedMutation<T3>,\r\n LrMutationBase<T4> | LrMergedMutation<T4>\r\n ]\r\n ): LrMergedMutation<[T1, T2, T3, T4]>;\r\n\r\n static create<T1, T2, T3, T4, T5>(\r\n lrMutations: [\r\n LrMutationBase<T1> | LrMergedMutation<T1>,\r\n LrMutationBase<T2> | LrMergedMutation<T2>,\r\n LrMutationBase<T3> | LrMergedMutation<T3>,\r\n LrMutationBase<T4> | LrMergedMutation<T4>,\r\n LrMutationBase<T5> | LrMergedMutation<T5>\r\n ]\r\n ): LrMergedMutation<[T1, T2, T3, T4, T5]>;\r\n\r\n static create(lrMutations: LrMutationBase<any>[]): LrMergedMutation<any[]>;\r\n\r\n static create(lrMutations: LrMutationBase<any>[]) {\r\n return new LrMergedMutation(lrMutations);\r\n }\r\n\r\n private getDescendants() {\r\n const ret = new Set<LrMutationBase<any>>();\r\n\r\n const addOrThrow = (item) => {\r\n if (ret.has(item)) {\r\n throw new LrBadLogicException(\r\n 'Classes that are derived from LrMutationBase can not be used more than once in a merged mutation.'\r\n );\r\n }\r\n\r\n ret.add(item);\r\n };\r\n\r\n this.lrMutations.forEach((lrMutation) => {\r\n if (lrMutation instanceof LrMutation) {\r\n addOrThrow(lrMutation);\r\n } else if (lrMutation instanceof LrMergedMutation) {\r\n lrMutation.descendants.forEach((t) => addOrThrow(t));\r\n } else {\r\n throw new LrUnsupportedException(\r\n `LrMergeMutation can not handle class: ${lrMutation.constructor.name}`\r\n );\r\n }\r\n });\r\n\r\n return ret;\r\n }\r\n\r\n resolve(value: any) {\r\n // Resolves any promises waiting for the child mutations\r\n for (let i = 0; i < this.lrMutations.length; ++i) {\r\n const prefix = this.prefixes[i];\r\n\r\n // Remove the prefix and resolve child mutation.\r\n const res: any = {};\r\n for (const key2 in value) {\r\n if (key2.startsWith(prefix)) {\r\n const originalKey = key2.slice(prefix.length);\r\n res[originalKey] = value[key2];\r\n }\r\n }\r\n this.lrMutations[i].resolve(res);\r\n }\r\n\r\n // Resolves to the result of children\r\n Promise.all(this.lrMutations.map((m) => m.promise)).then(\r\n (childValues: any) => {\r\n // Resolves any promises waiting for the current merged mutation\r\n super.resolve(childValues);\r\n }\r\n );\r\n }\r\n\r\n reject(reason?: any) {\r\n super.reject(reason);\r\n this.lrMutations.forEach((lrMutation) => lrMutation.reject(reason));\r\n }\r\n\r\n setExecuted() {\r\n super.setExecuted();\r\n this.lrMutations.forEach((lrMutation) => lrMutation.setExecuted());\r\n }\r\n\r\n private renameVariableDefinition(varDef: VariableDefinitionNode, prefix) {\r\n return {\r\n ...varDef,\r\n variable: {\r\n ...varDef.variable,\r\n name: ast.name(prefix + varDef.variable.name.value),\r\n },\r\n };\r\n }\r\n\r\n private renameVariableDefinitions(\r\n varDefs: ReadonlyArray<VariableDefinitionNode>,\r\n prefix\r\n ) {\r\n return varDefs.map((varDef) =>\r\n this.renameVariableDefinition(varDef, prefix)\r\n );\r\n }\r\n\r\n private renameArgument(arg: ArgumentNode, prefix) {\r\n if (arg.value.kind !== 'Variable') {\r\n return arg;\r\n }\r\n\r\n return {\r\n ...arg,\r\n value: {\r\n ...arg.value,\r\n name: ast.name(prefix + arg.value.name.value),\r\n },\r\n };\r\n }\r\n\r\n private renameField(selection: FieldNode, prefix): FieldNode {\r\n // Only handling type Field\r\n if (selection.kind !== 'Field') {\r\n return selection;\r\n }\r\n\r\n const alias = prefix + getAliasOrName(selection);\r\n const args = selection.arguments.map((arg) =>\r\n this.renameArgument(arg, prefix)\r\n );\r\n\r\n return {\r\n ...selection,\r\n alias: {\r\n kind: 'Name',\r\n value: alias,\r\n },\r\n arguments: args,\r\n };\r\n }\r\n\r\n private renameFragmentSpread(\r\n selection: FragmentSpreadNode,\r\n prefix\r\n ): FragmentSpreadNode {\r\n return {\r\n ...selection,\r\n name: ast.name(prefix + selection.name.value),\r\n };\r\n }\r\n\r\n private processSelection(selection: SelectionNode, prefix): SelectionNode {\r\n switch (selection.kind) {\r\n case 'FragmentSpread':\r\n return this.renameFragmentSpread(selection, prefix);\r\n case 'Field':\r\n // Continue to process children for nested selections.\r\n if (selection.selectionSet) {\r\n return {\r\n ...selection,\r\n selectionSet: this.processSelectionSet(\r\n selection.selectionSet,\r\n prefix\r\n ),\r\n };\r\n } else {\r\n return selection;\r\n }\r\n default:\r\n return selection;\r\n }\r\n }\r\n\r\n private processSelectionSet(\r\n selectionSet: SelectionSetNode,\r\n prefix\r\n ): SelectionSetNode {\r\n return {\r\n ...selectionSet,\r\n selections: selectionSet.selections.map((selection) =>\r\n this.processSelection(selection, prefix)\r\n ),\r\n };\r\n }\r\n\r\n private renameSelections(\r\n selections: ReadonlyArray<SelectionNode>,\r\n prefix\r\n ): SelectionNode[] {\r\n return selections.map((selection) => {\r\n switch (selection.kind) {\r\n case 'Field':\r\n const field = this.renameField(selection, prefix);\r\n return this.processSelection(field, prefix);\r\n default:\r\n return selection;\r\n }\r\n });\r\n }\r\n\r\n private renameFragmentDefinition(fragment: FragmentDefinitionNode, prefix) {\r\n const ret = {\r\n ...fragment,\r\n name: ast.name(prefix + fragment.name.value),\r\n };\r\n\r\n if (fragment.selectionSet) {\r\n ret.selectionSet = this.processSelectionSet(\r\n fragment.selectionSet,\r\n prefix\r\n );\r\n }\r\n\r\n return ret;\r\n }\r\n\r\n private renameFragmentDefinitions(\r\n fragments: FragmentDefinitionNode[],\r\n prefix\r\n ) {\r\n return fragments.map((fragment) =>\r\n this.renameFragmentDefinition(fragment, prefix)\r\n );\r\n }\r\n\r\n private merge() {\r\n let variableDefinitions: VariableDefinitionNode[] = [];\r\n let selections: SelectionNode[] = [];\r\n const mergedVariables = {};\r\n let mergedFragments: FragmentDefinitionNode[] = [];\r\n\r\n const prefixes: string[] = [];\r\n\r\n // Just wait for everything to resolve because we have to\r\n // merge the doc synchronously.\r\n this.lrMutations.forEach((lrMutation, idx) => {\r\n const { mutation, variables } = lrMutation.lrMutationData;\r\n\r\n const childMutationNode = getMutation(mutation);\r\n\r\n // Prefixing all mutation fields so they don't conflict.\r\n let prefix = `item${idx}_`;\r\n if (childMutationNode.name) {\r\n prefix += childMutationNode.name.value + '_';\r\n }\r\n\r\n prefixes.push(prefix);\r\n\r\n // Rename and merge variables\r\n variableDefinitions = [\r\n ...variableDefinitions,\r\n ...this.renameVariableDefinitions(\r\n childMutationNode.variableDefinitions,\r\n prefix\r\n ),\r\n ];\r\n\r\n // Rename and merge selections\r\n selections = [\r\n ...selections,\r\n ...this.renameSelections(\r\n childMutationNode.selectionSet.selections,\r\n prefix\r\n ),\r\n ];\r\n\r\n // TODO Rename and merge fragments\r\n\r\n // Rename and merge variables\r\n for (const key2 of Object.keys(variables)) {\r\n mergedVariables[prefix + key2] = variables[key2];\r\n }\r\n\r\n // Rename and merge fragments\r\n const fragments = getFragments(mutation);\r\n mergedFragments = [\r\n ...mergedFragments,\r\n ...this.renameFragmentDefinitions(fragments, prefix),\r\n ];\r\n });\r\n\r\n const mergedMutation: DocumentNode = lodash.cloneDeep(lrMergedMutationDoc);\r\n const mutationNode = getMutation(mergedMutation);\r\n // Add in the mutation selections\r\n mutationNode.selectionSet.selections = selections;\r\n // Add in the variables\r\n // variableDefinitions is readonly property.\r\n (mutationNode as any).variableDefinitions = variableDefinitions;\r\n // Add in the fragments\r\n (mergedMutation as any).definitions = [\r\n ...mergedMutation.definitions,\r\n ...mergedFragments,\r\n ];\r\n\r\n return {\r\n mutation: mergedMutation,\r\n variables: mergedVariables,\r\n prefixes,\r\n };\r\n }\r\n}\r\n","import * as lodash from 'lodash';\r\nimport { Injectable, NgZone } from '@angular/core';\r\nimport { Apollo } from 'apollo-angular';\r\nimport {\r\n QueryOptions,\r\n MutationOptions,\r\n OperationVariables,\r\n FetchPolicy,\r\n} from '@apollo/client/core';\r\nimport { MutationBaseOptions } from '@apollo/client/core/watchQueryOptions';\r\nimport { KeyGraphService } from '../../cryptography/key-graph.service';\r\nimport { HasKeyGraph } from '../../cryptography/cryptography.types';\r\nimport {\r\n handleApolloError,\r\n LrBadStateException,\r\n LrUnsupportedException,\r\n} from '../../_common/exceptions';\r\nimport { FetchKeyGraphField, KeyGraphField } from '../../_common/queries.gql';\r\nimport { TypedDocumentNode, getQuery, getMutation } from '../../_common/ast';\r\nimport gql from 'graphql-tag';\r\nimport { ProcessorOptions, QueryProcessorService } from '../query-processor';\r\nimport { RunOutsideAngular } from '../../_common/run-outside-angular';\r\nimport { FieldNode } from 'graphql';\r\nimport { LrMutationBase } from './lr-mutation-base';\r\nimport * as gqlPrinter from 'graphql/language/printer';\r\nimport { LrMergedMutation } from './lr-merged-mutation';\r\n\r\n// Data structures\r\n// --------------------------------------------------------------------------\r\nconst keyGraphFieldAstSelection = getQuery(gql`\r\nquery {\r\n ${KeyGraphField}\r\n}\r\n`).selectionSet.selections[0] as FieldNode;\r\n\r\nconst fetchKeyGraphFieldAstSelection = getQuery(gql`\r\nquery {\r\n ${FetchKeyGraphField}\r\n}\r\n`).selectionSet.selections[0] as FieldNode;\r\n\r\n// const keyGraphFieldAstSelection = () =>\r\n// lodash.deepClone(_keyGraphFieldAstSelection) as FieldNode;\r\n// const fetchKeyGraphFieldAstSelection = () =>\r\n// lodash.deepClone(_fetchKeyGraphFieldAstSelection) as FieldNode;\r\n\r\nexport interface LrQueryOptions<T, TVariables>\r\n extends QueryOptions<TVariables> {\r\n query: TypedDocumentNode<T>;\r\n includeKeyGraph?: boolean;\r\n processorOptions?: ProcessorOptions;\r\n}\r\n\r\n// Copied from MutationOptions\r\n// Removed required field \"mutation\". The \"variables\" field is still there\r\n// but it's dynamically checked.\r\nexport interface LrMutationOptions<\r\n T = {\r\n [key: string]: any;\r\n },\r\n TVariables = OperationVariables\r\n> extends MutationBaseOptions<T, TVariables> {\r\n context?: any;\r\n fetchPolicy?: FetchPolicy;\r\n includeKeyGraph?: boolean;\r\n}\r\n\r\n// The \"mutation\" and \"variable\" fields are inherited but dynamically prohibited because\r\n// they are provided by LrMutation. It's a bit unclean but avoids a lot of typing work.\r\nexport interface LrApolloMutationOptions<T, TVariables = OperationVariables>\r\n extends MutationOptions<T, TVariables> {\r\n mutation: TypedDocumentNode<T>;\r\n includeKeyGraph?: boolean;\r\n processorOptions?: ProcessorOptions;\r\n}\r\n\r\ninterface LrGraphQLServiceStats {\r\n queryCount: number;\r\n mutationCount: number;\r\n}\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class LrGraphQLService {\r\n private stats: LrGraphQLServiceStats = {\r\n queryCount: 0,\r\n mutationCount: 0,\r\n };\r\n\r\n constructor(\r\n private ngZone: NgZone,\r\n private apollo: Apollo,\r\n private keyGraph: KeyGraphService,\r\n private queryProcessor: QueryProcessorService\r\n ) {}\r\n\r\n async query<T, V = { [key: string]: any }>(\r\n options: LrQueryOptions<T, V>\r\n ): Promise<T> {\r\n // Make copies to avoid side effect.\r\n options = lodash.cloneDeep(options);\r\n\r\n // Append the key graph query\r\n const includeKeyGraph = this.isIncludeKeyGraph(options.includeKeyGraph);\r\n if (includeKeyGraph) {\r\n const operation = getQuery(options.query);\r\n operation.selectionSet.selections = [\r\n ...operation.selectionSet.selections,\r\n keyGraphFieldAstSelection,\r\n ];\r\n }\r\n\r\n const response = await this.apollo.query<T, V>(options).toPromise();\r\n\r\n this.stats.queryCount++;\r\n\r\n handleApolloError(response.errors);\r\n\r\n this.addKeys(response);\r\n\r\n const data = await this.queryProcessor.processQuery(\r\n response.data,\r\n options.processorOptions\r\n );\r\n\r\n return data;\r\n }\r\n\r\n private async lrMutateImpl(lrMutation, options?) {\r\n if (options?.variables) {\r\n throw new LrUnsupportedException(\r\n 'Unsupported field: \"options.variables\"'\r\n );\r\n }\r\n\r\n if (lrMutation.executed) {\r\n throw new LrBadStateException(\r\n 'LrMutation has already executed. LrMutation can only be used once in a lrMutate() call. Create new instances of LrMutation.'\r\n );\r\n }\r\n\r\n lrMutation.setExecuted();\r\n\r\n return this.apolloMutate({\r\n ...options,\r\n ...lrMutation.lrMutationData,\r\n })\r\n .then((res) => {\r\n // Resolve promises set on the lrMutation rather than the lrMutate() call.\r\n lrMutation.resolve(res);\r\n // Still need to return value to the promise waiting for the results of lrMutate().\r\n return res;\r\n })\r\n .catch((error) => {\r\n lrMutation.reject(error);\r\n throw error;\r\n });\r\n }\r\n\r\n async apolloMutate<T extends any, TVariables = { [key: string]: any }>(\r\n options: LrApolloMutationOptions<T, TVariables>\r\n ): Promise<T> {\r\n // Make copies to avoid side effect.\r\n options = {\r\n ...options,\r\n mutation: lodash.cloneDeep(options.mutation),\r\n };\r\n\r\n // Append the key graph query\r\n const includeKeyGraph = this.isIncludeKeyGraph(options.includeKeyGraph);\r\n\r\n if (includeKeyGraph) {\r\n const operation = getMutation(options.mutation);\r\n operation.selectionSet.selections = [\r\n ...operation.selectionSet.selections,\r\n fetchKeyGraphFieldAstSelection,\r\n ];\r\n }\r\n\r\n // Format to string and parse again. This allows the \"loc\": { \"start\": ... }\r\n // part of the DocumentNode to be correctly setup. It's extra processing\r\n // in serialising and parsing, but probably minimal overhead.\r\n options.mutation = gql(gqlPrinter.print(options.mutation));\r\n\r\n const response = await this.apollo.mutate<T>(options).toPromise();\r\n\r\n this.stats.mutationCount++;\r\n\r\n handleApolloError(response.errors);\r\n\r\n this.addKeys(response);\r\n\r\n const data = await this.queryProcessor.processQuery(\r\n response.data,\r\n options.processorOptions\r\n );\r\n\r\n return data;\r\n }\r\n\r\n statsSnapshot(): LrGraphQLServiceStats {\r\n return lodash.cloneDeep(this.stats);\r\n }\r\n\r\n private addKeys(response) {\r\n if ((response.data as HasKeyGraph).keyGraph) {\r\n this.keyGraph.addKeys((response.data as HasKeyGraph).keyGraph);\r\n delete response.data.keyGraph;\r\n }\r\n }\r\n\r\n private isIncludeKeyGraph(includeKeyGraph) {\r\n // Default to true when null or undefined.\r\n return includeKeyGraph == null ? true : false;\r\n }\r\n\r\n async lrMutate<T1, TVariables1, T2, TVariables2>(\r\n lrMutations: [\r\n LrMutationMayAsync<T1, TVariables1>,\r\n LrMutationMayAsync<T2, TVariables2>\r\n ],\r\n options?: LrMutationOptions\r\n ): Promise<[T1, T2]>;\r\n\r\n async lrMutate<T1, TVariables1, T2, TVariables2, T3, TVariables3>(\r\n lrMutations: [\r\n LrMutationMayAsync<T1, TVariables1>,\r\n LrMutationMayAsync<T2, TVariables2>,\r\n LrMutationMayAsync<T3, TVariables3>\r\n ],\r\n options?: LrMutationOptions\r\n ): Promise<[T1, T2, T3]>;\r\n\r\n async lrMutate<\r\n T1,\r\n TVariables1,\r\n T2,\r\n TVariables2,\r\n T3,\r\n TVariables3,\r\n T4,\r\n TVariables4\r\n >(\r\n lrMutations: [\r\n LrMutationMayAsync<T1, TVariables1>,\r\n LrMutationMayAsync<T2, TVariables2>,\r\n LrMutationMayAsync<T3, TVariables3>,\r\n LrMutationMayAsync<T4, TVariables4>\r\n ],\r\n options?: LrMutationOptions\r\n ): Promise<[T1, T2, T3, T4]>;\r\n\r\n async lrMutate<\r\n T1,\r\n TVariables1,\r\n T2,\r\n TVariables2,\r\n T3,\r\n TVariables3,\r\n T4,\r\n TVariables4,\r\n T5,\r\n TVariables5\r\n >(\r\n lrMutations: [\r\n LrMutationMayAsync<T1, TVariables1>,\r\n LrMutationMayAsync<T2, TVariables2>,\r\n LrMutationMayAsync<T3, TVariables3>,\r\n LrMutationMayAsync<T4, TVariables4>,\r\n LrMutationMayAsync<T5, TVariables5>\r\n ],\r\n options?: LrMutationOptions\r\n ): Promise<[T1, T2, T3, T4, T5]>;\r\n\r\n async lrMutate<T, TVariables = { [key: string]: any }>(\r\n lrMutation: LrMutationMayAsync<T, TVariables>,\r\n options?: LrMutationOptions<T, TVariables>\r\n ): Promise<T>;\r\n\r\n async lrMutate<T, TVariables = { [key: string]: any }>(\r\n lrMutations:\r\n | LrMutationMayAsync<T, TVariables>[]\r\n | LrMutationMayAsync<T, TVariables>,\r\n options?: LrMutationOptions\r\n );\r\n\r\n async lrMutate<T, TVariables = { [key: string]: any }>(\r\n lrMutations:\r\n | LrMutationMayAsync<T, TVariables>[]\r\n | LrMutationMayAsync<T, TVariables>,\r\n options?: LrMutationOptions\r\n ) {\r\n if (lrMutations instanceof Array) {\r\n const merged = LrMergedMutation.create(await Promise.all(lrMutations));\r\n await this.lrMutateImpl(merged, options);\r\n return merged.promise;\r\n } else {\r\n const resolved = await lrMutations;\r\n await this.lrMutateImpl(resolved, options);\r\n return resolved.promise;\r\n }\r\n }\r\n}\r\n\r\ntype LrMutationMayAsync<T, TVariables> =\r\n | LrMutationBase<T, TVariables>\r\n | Promise<LrMutationBase<T, TVariables>>\r\n | LrMergedMutation<T>\r\n | Promise<LrMergedMutation<T>>;\r\n","import { Injector } from '@angular/core';\r\nimport {\r\n LrGraphQLService,\r\n LrMutationOptions,\r\n LrQueryOptions,\r\n} from './lr-graphql.service';\r\nimport { LrMutationBase } from './lr-mutation-base';\r\n\r\nexport class LrService {\r\n protected lrGraphQL: LrGraphQLService;\r\n\r\n constructor(injector: Injector) {\r\n this.lrGraphQL = injector.get(LrGraphQLService);\r\n }\r\n\r\n protected async mutate<T, TVariables>(\r\n lrMutation:\r\n | LrMutationBase<T, TVariables>\r\n | Promise<LrMutationBase<T, TVariables>>,\r\n options?: LrMutationOptions<T, TVariables>\r\n ) {\r\n return this.lrGraphQL.lrMutate(lrMutation, options);\r\n }\r\n\r\n protected async query<T, V>(options: LrQueryOptions<T, V>) {\r\n return this.lrGraphQL.query(options);\r\n }\r\n}\r\n","import { Inject, Injectable, isDevMode } from '@angular/core';\r\nimport { CognitoUser } from '@aws-amplify/auth';\r\nimport { Hub } from '@aws-amplify/core';\r\nimport { CognitoUserAttribute } from 'amazon-cognito-identity-js';\r\nimport { Observable, ReplaySubject } from 'rxjs';\r\nimport { PassIdpParams } from '../cryptography/cryptography.types';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport { ProfileService } from '../users/profile.service';\r\nimport { PasswordChangeStatus } from '../users/profile.types';\r\nimport {\r\n LrConcurrentAccessException,\r\n LrBadRequestException,\r\n} from '../_common/exceptions';\r\nimport {\r\n CognitoChallengeUser,\r\n CurrentUser,\r\n TpPasswordResetUser,\r\n LoginResult,\r\n RecoveryStatus,\r\n} from './auth.types';\r\nimport { PasswordService } from './password.service';\r\nimport { AuthClass } from '@aws-amplify/auth/lib-esm/Auth';\r\nimport { TpPasswordResetUserQuery } from '../trusted-parties/tp-password-reset.gql';\r\nimport { IdleService } from './idle.service';\r\nimport { KeyFactoryService } from '../cryptography/key-factory.service';\r\nimport { LrGraphQLService, LrMutation } from '../api/lr-graphql';\r\nimport { TpPasswordResetUserNode } from '../api/types';\r\nimport { TpPasswordResetProcessorService } from '../api/query-processor/tp-password-reset-processor.service';\r\nimport { SetSessionEncryptionKeyMutation } from './auth.gql';\r\nimport { PersistService } from '../api/persist.service';\r\nimport { JWK } from 'node-jose';\r\nimport { LifeReadyConfig, LR_CONFIG } from '../life-ready.config';\r\n\r\nexport const initialiseAuth = (authService: LifeReadyAuthService) => {\r\n return () => authService.initialise();\r\n};\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class LifeReadyAuthService {\r\n private hubSubject: ReplaySubject<any> = new ReplaySubject<any>(1);\r\n private currentUser: CurrentUser;\r\n\r\n constructor(\r\n @Inject(LR_CONFIG) private config: LifeReadyConfig,\r\n private auth: AuthClass,\r\n private keyFactory: KeyFactoryService,\r\n private keyService: KeyService,\r\n private profileService: ProfileService,\r\n private keyGraphService: KeyGraphService,\r\n private passwordService: PasswordService,\r\n private idleService: IdleService,\r\n private lrGraphQL: LrGraphQLService,\r\n private tpPasswordResetProcessorService: TpPasswordResetProcessorService,\r\n private persistService: PersistService\r\n ) {}\r\n\r\n public async initialise() {\r\n Hub.listen('auth', (data) => this.hubSubject.next(data.payload));\r\n }\r\n\r\n private async loginIdpImpl(\r\n emailOrPhone: string,\r\n password: string,\r\n passIdpParams: PassIdpParams,\r\n recoveryStatus: RecoveryStatus\r\n ): Promise<CognitoChallengeUser> {\r\n const passIdpResult = await this.keyFactory.derivePassIdp({\r\n password,\r\n ...passIdpParams,\r\n });\r\n // Use the derived password to signin with cognito\r\n const user = await this.auth.signIn(\r\n emailOrPhone,\r\n this.passwordService.getPassIdpString(passIdpResult.jwk)\r\n );\r\n\r\n user.recoveryStatus = recoveryStatus;\r\n\r\n return user;\r\n }\r\n\r\n private async loginIdp(\r\n emailOrPhone: string,\r\n password: string\r\n ): Promise<CognitoChallengeUser> {\r\n // Download the salt needed to derive the PassIdp\r\n const passIdpApiResult = await this.profileService.getPassIdpParams(\r\n emailOrPhone\r\n );\r\n\r\n if (\r\n passIdpApiResult.passwordChangeStatus === PasswordChangeStatus.InProgress\r\n ) {\r\n throw new LrConcurrentAccessException('A password change is in progress');\r\n }\r\n\r\n if (\r\n passIdpApiResult.passwordChangeStatus === PasswordChangeStatus.Recovery\r\n ) {\r\n console.log('In recovery mode.');\r\n // Let's say we don't know if the password is the new one or the old one. We just have to try both.\r\n try {\r\n const user = await this.loginIdpImpl(\r\n emailOrPhone,\r\n password,\r\n passIdpApiResult.newPassIdpParams,\r\n RecoveryStatus.NEW_PASSWORD\r\n );\r\n // New password worked. Let's set to the current password\r\n\r\n // --Potential Failure Point 1--\r\n // if changePasswordComplete() doesn't get called, then it should remain\r\n\r\n console.log('New password works!');\r\n\r\n return user;\r\n } catch (error) {\r\n // Just bubble up any other type of error.\r\n if (error.code !== 'NotAuthorizedException') {\r\n throw error;\r\n }\r\n // pass, try again assuming it's the old password\r\n }\r\n\r\n // Now assume it's the previous password. Any exception is allowed to bubble up.\r\n try {\r\n const user = await this.loginIdpImpl(\r\n emailOrPhone,\r\n password,\r\n passIdpApiResult.currentPassIdpParams,\r\n RecoveryStatus.OLD_PASSWORD\r\n );\r\n // Old password worked.\r\n console.log('Old password works!');\r\n\r\n return user;\r\n } catch (error) {\r\n // Just bubble up any other type of error.\r\n throw error.code === 'NotAuthorizedException'\r\n ? new LrBadRequestException(\r\n 'The password change request was interrupted, please try to login with both your new and old password'\r\n )\r\n : error;\r\n }\r\n }\r\n\r\n // Try against as the TP password reset account\r\n if (passIdpApiResult.tpPasswordReset) {\r\n try {\r\n // TP password reset is in process. We need to try the password against both\r\n // original account and the new reset account.\r\n const reset = passIdpApiResult.tpPasswordReset;\r\n const ret = await this.loginIdpImpl(\r\n reset.resetUsername,\r\n password,\r\n reset.passIdpParams,\r\n RecoveryStatus.NONE\r\n );\r\n ret.isTpPasswordResetUser = true;\r\n\r\n return ret;\r\n } catch (err) {\r\n // continue, try again as regular user.\r\n }\r\n }\r\n\r\n // Login as regular user\r\n return await this.loginIdpImpl(\r\n emailOrPhone,\r\n password,\r\n passIdpApiResult.currentPassIdpParams,\r\n RecoveryStatus.NONE\r\n );\r\n }\r\n\r\n protected async handleSessionEncryptionKey() {\r\n if (this.config.disableSessionEncryptionKey) {\r\n if (!isDevMode()) {\r\n const msg =\r\n 'You should not set disableSessionEncryptionKey=True in mode prod. It defaults to false.';\r\n console.error(msg);\r\n throw new Error(msg);\r\n } else {\r\n console.warn(\r\n 'You have set disableSessionEncryptionKey=True. Make sure not to do this in prod mode.'\r\n );\r\n }\r\n } else {\r\n // Set the session key to a new encryption key for this session\r\n const sessionEncryptionKey = await this.keyFactory.createKey();\r\n await this.lrGraphQL.lrMutate(\r\n new LrMutation({\r\n mutation: SetSessionEncryptionKeyMutation,\r\n variables: {\r\n input: {\r\n sessionEncryptionKey: JSON.stringify(\r\n sessionEncryptionKey.toJSON(true)\r\n ),\r\n },\r\n },\r\n }),\r\n {\r\n includeKeyGraph: false,\r\n }\r\n );\r\n\r\n this.persistService.setServerSessionEncryptionKey(sessionEncryptionKey);\r\n }\r\n }\r\n\r\n protected async handlePostAuth(cognitoUser: CognitoChallengeUser) {\r\n await this.handlePasswordRecovery(cognitoUser);\r\n await this.handleSessionEncryptionKey();\r\n }\r\n\r\n public async login(\r\n emailOrPhone: string,\r\n password: string\r\n ): Promise<LoginResult> {\r\n const cognitoUser = await this.loginIdp(emailOrPhone, password);\r\n\r\n // todo: Meet MFA challenges.\r\n if (['SMS_MFA', 'SOFTWARE_TOKEN_MFA'].includes(cognitoUser.challengeName)) {\r\n return { hasChallenge: true, challenge: cognitoUser };\r\n }\r\n\r\n await this.handlePostAuth(cognitoUser);\r\n\r\n if (cognitoUser.isTpPasswordResetUser) {\r\n // Assuming there is no MFA on the TP reset user.\r\n const resetUser = await this.loadResetUser(password);\r\n return { hasChallenge: false, resetUser };\r\n } else {\r\n const user = await this.loadUser(cognitoUser, password);\r\n await this.idleService.start(); // Run idleService whenever user is logged in.\r\n return { hasChallenge: false, user };\r\n }\r\n }\r\n\r\n // TODO <AZ> We need to handle the isTpPasswordResetUser=True case here after MFA as well.\r\n public async verifyLogin(\r\n challenge: CognitoChallengeUser,\r\n password: string,\r\n rememberMe: boolean,\r\n code: string\r\n ): Promise<CurrentUser> {\r\n await this.auth.confirmSignIn(challenge, code, challenge.challengeName);\r\n\r\n // TODO: this.auth.confirmSignIn() could return another challenge.\r\n\r\n const cognitoUser: CognitoUser = await this.auth.currentAuthenticatedUser();\r\n\r\n await this.handlePostAuth(challenge);\r\n\r\n const user = await this.loadUser(cognitoUser, password);\r\n\r\n if (rememberMe) {\r\n cognitoUser.setDeviceStatusRemembered({\r\n onSuccess: () => {},\r\n onFailure: (e) => console.error(e),\r\n });\r\n }\r\n\r\n return user;\r\n }\r\n\r\n async handlePasswordRecovery(user: CognitoChallengeUser) {\r\n if (user.recoveryStatus !== RecoveryStatus.NONE) {\r\n const jwtToken = user\r\n .getSignInUserSession()\r\n .getAccessToken()\r\n .getJwtToken();\r\n await this.passwordService.changePasswordComplete(\r\n jwtToken,\r\n user.recoveryStatus === RecoveryStatus.NEW_PASSWORD\r\n );\r\n }\r\n }\r\n\r\n async getUser(reload: boolean = false): Promise<CurrentUser> {\r\n if (!reload && this.currentUser) {\r\n return this.currentUser;\r\n }\r\n this.currentUser = await this.loadUser(\r\n await this.auth.currentAuthenticatedUser()\r\n );\r\n console.log('Starting idle service.');\r\n await this.idleService.start(); // Run idleService whenever user is logged in.\r\n return this.currentUser;\r\n }\r\n\r\n private mapTPVaultAccess(features?: any): boolean {\r\n const tpVaultFeature = features?.tpVault;\r\n return (\r\n tpVaultFeature?.length > 0 &&\r\n tpVaultFeature.some((feature) => feature.toUpperCase() === 'ACCESS')\r\n );\r\n }\r\n\r\n private async loadUser(\r\n cognitoUser: CognitoUser,\r\n password?: string\r\n ): Promise<CurrentUser> {\r\n const {\r\n currentUser,\r\n contactCard,\r\n userPlans,\r\n } = await this.profileService.getCurrentUser();\r\n\r\n if (currentUser.sessionEncryptionKey) {\r\n this.persistService.setServerSessionEncryptionKey(\r\n await JWK.asKey(currentUser.sessionEncryptionKey)\r\n );\r\n }\r\n\r\n const userAttributes = await this.auth.userAttributes(cognitoUser);\r\n\r\n if (password) {\r\n const passKey = (\r\n await this.keyFactory.derivePassKey({\r\n password,\r\n ...currentUser.currentUserKey.passKey.passKeyParams,\r\n })\r\n ).jwk;\r\n\r\n await this.idleService.persistMasterKey(\r\n await this.keyGraphService.unwrapWithPassKey(\r\n currentUser.currentUserKey.passKey.id,\r\n passKey,\r\n currentUser.currentUserKey.masterKey.id\r\n )\r\n );\r\n }\r\n await this.keyGraphService.populateKeys(currentUser.currentUserKey);\r\n\r\n return {\r\n id: currentUser.id,\r\n sub: this.getUserAttribute('sub', userAttributes),\r\n username: currentUser.username,\r\n currentUserKey: currentUser.currentUserKey,\r\n getAccessJwtToken: () =>\r\n cognitoUser.getSignInUserSession().getAccessToken().getJwtToken(),\r\n email: this.getUserAttribute('email', userAttributes),\r\n emailVerified:\r\n this.getUserAttribute('email_verified', userAttributes) === 'true',\r\n phone: this.getUserAttribute('phone_number', userAttributes),\r\n phoneVerified:\r\n this.getUserAttribute('phone_number_verified', userAttributes) ===\r\n 'true',\r\n contactCard: {\r\n ...(await this.profileService.decryptContactCard(contactCard)),\r\n },\r\n userDelete: currentUser.userDelete,\r\n userPlans,\r\n hasTPVaultAccess: this.mapTPVaultAccess(currentUser.features),\r\n features: currentUser.features,\r\n sessionEncryptionKey: currentUser.sessionEncryptionKey,\r\n };\r\n }\r\n\r\n public watchAuth(): Observable<any> {\r\n return this.hubSubject;\r\n }\r\n\r\n public async logout(): Promise<void> {\r\n this.currentUser = null;\r\n this.keyService.purgeKeys();\r\n this.keyGraphService.purgeKeys();\r\n\r\n await Promise.all([this.auth.signOut(), this.profileService.signOut()]);\r\n }\r\n\r\n private getUserAttribute(\r\n attributeName: string,\r\n userAttributes: CognitoUserAttribute[]\r\n ) {\r\n const userAttribute = userAttributes.find(\r\n (x) => x.getName() === attributeName\r\n );\r\n\r\n return userAttribute ? userAttribute.getValue() : null;\r\n }\r\n\r\n public async loadResetUser(password?: string): Promise<TpPasswordResetUser> {\r\n const { tpPasswordResetUser: resetUser } = await this.lrGraphQL.query({\r\n query: TpPasswordResetUserQuery,\r\n });\r\n\r\n if (resetUser.sessionEncryptionKey) {\r\n this.persistService.setServerSessionEncryptionKey(\r\n await JWK.asKey(resetUser.sessionEncryptionKey)\r\n );\r\n }\r\n\r\n // Update the keys\r\n if (password) {\r\n const passKey = (\r\n await this.keyFactory.derivePassKey({\r\n password,\r\n ...resetUser.passKey.passKeyParams,\r\n })\r\n ).jwk;\r\n\r\n await this.idleService.persistMasterKey(\r\n await this.keyGraphService.unwrapWithPassKey(\r\n resetUser.passKey.id,\r\n passKey,\r\n resetUser.masterKey.id\r\n )\r\n );\r\n }\r\n\r\n this.keyService.populateKeys({\r\n passKey: {\r\n id: resetUser.passKey.id,\r\n },\r\n masterKey: {\r\n id: resetUser.masterKey.id,\r\n },\r\n });\r\n\r\n const userAttributes = await this.auth.userAttributes(\r\n await this.auth.currentAuthenticatedUser()\r\n );\r\n const sub = this.getUserAttribute('sub', userAttributes);\r\n\r\n return {\r\n ...(await this.tpPasswordResetProcessorService.processTpPasswordResetUserNode(\r\n resetUser\r\n )),\r\n sub,\r\n };\r\n }\r\n\r\n public async refreshAccessToken() {\r\n const cognitoUser: CognitoUser = await this.auth.currentAuthenticatedUser();\r\n const refreshToken = cognitoUser.getSignInUserSession().getRefreshToken();\r\n\r\n return new Promise((resolve, reject) => {\r\n cognitoUser.refreshSession(refreshToken, (err, data) => {\r\n if (err) {\r\n console.error('Error refreshing token: ', err);\r\n reject(err);\r\n } else {\r\n console.log('Token refresh complete: ', data);\r\n resolve(0);\r\n }\r\n });\r\n });\r\n }\r\n}\r\n","import { HttpClient } from '@angular/common/http';\r\nimport { Injectable, Inject } from '@angular/core';\r\nimport { LR_CONFIG, LifeReadyConfig } from '../life-ready.config';\r\nimport { LifeReadyAuthService } from '../auth/life-ready-auth.service';\r\n\r\nexport type FileContentContext = 'FILE_STATE';\r\n\r\nexport interface UploadEncryptedFileOptions {\r\n encryptedContent: string;\r\n // TODO Add in the context field and make it mandatory\r\n // context: FileContentContext;\r\n fileName?: string;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class FileService {\r\n constructor(\r\n @Inject(LR_CONFIG) private config: LifeReadyConfig,\r\n private http: HttpClient,\r\n private lrAuth: LifeReadyAuthService\r\n ) {}\r\n\r\n async downloadEncryptedFile(fileStateNodeId: string): Promise<any> {\r\n return JSON.parse(await this.downloadEncryptedFile2(fileStateNodeId));\r\n }\r\n\r\n async downloadEncryptedFile2(fileStateNodeId: string): Promise<string> {\r\n const url = `${this.config.apiUrl}files/download/?file_state_node_id=${fileStateNodeId}`;\r\n\r\n const content = await this.http\r\n .get(url, {\r\n responseType: 'text',\r\n headers: {\r\n Authorization: `Bearer ${(\r\n await this.lrAuth.getUser()\r\n ).getAccessJwtToken()}`,\r\n },\r\n })\r\n .toPromise();\r\n\r\n return content;\r\n }\r\n\r\n async loadFile(file: File): Promise<ArrayBuffer> {\r\n return new Promise<ArrayBuffer>((resolve, reject) => {\r\n const reader = new FileReader();\r\n reader.onload = () => {\r\n // OK to type cast here since we are using readAsArrayBuffer.\r\n resolve(reader.result as ArrayBuffer);\r\n };\r\n reader.readAsArrayBuffer(file);\r\n });\r\n }\r\n\r\n async uploadEncryptedFile(\r\n options: UploadEncryptedFileOptions\r\n ): Promise<string> {\r\n const { encryptedContent, fileName } = options;\r\n\r\n const formData = new FormData();\r\n formData.append('content', new Blob([encryptedContent]), fileName);\r\n\r\n const { content_resource } = await this.http\r\n .post<{ content_resource }>(\r\n `${this.config.apiUrl}files/upload/`,\r\n formData,\r\n {\r\n headers: {\r\n Authorization: `Bearer ${(\r\n await this.lrAuth.getUser()\r\n ).getAccessJwtToken()}`,\r\n },\r\n }\r\n )\r\n .toPromise();\r\n\r\n return content_resource;\r\n }\r\n}\r\n","import gql from 'graphql-tag';\r\nimport { User } from './user.types';\r\nimport { HasKeyGraph } from '../cryptography/cryptography.types';\r\n\r\nexport interface UserQueryType extends HasKeyGraph {\r\n user: User;\r\n}\r\n\r\nexport const UserQuery = gql`\r\n query UserQuery($email: LrEmail, $username: String) {\r\n user(email: $email, username: $username) {\r\n id\r\n username\r\n haveTp\r\n isCurrentUser\r\n contactCards {\r\n edges {\r\n node {\r\n publicData\r\n publicSearchable\r\n }\r\n }\r\n }\r\n currentUserKey {\r\n sigPxk {\r\n id\r\n pbk\r\n }\r\n pxk {\r\n id\r\n pbk\r\n }\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const RequestUserDeleteMutation = gql`\r\n mutation RequestUserDelete($input: RequestUserDeleteInput!) {\r\n requestUserDelete(input: $input) {\r\n userDelete {\r\n state\r\n created\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const CancelUserDeleteMutation = gql`\r\n mutation CancelUserDelete($input: CancelUserDeleteInput!) {\r\n cancelUserDelete(input: $input) {\r\n id\r\n }\r\n }\r\n`;\r\n\r\nexport const LoginHistoryQuery = gql`\r\n query LoginHistory($first: Int, $after: String) {\r\n loginHistory(first: $first, after: $after) {\r\n pageInfo {\r\n hasNextPage\r\n hasPreviousPage\r\n startCursor\r\n endCursor\r\n }\r\n events\r\n }\r\n }\r\n`;\r\n","import { Injectable } from '@angular/core';\r\nimport { User, GetUserInput, UserDelete } from './user.types';\r\nimport {\r\n UserQuery,\r\n UserQueryType,\r\n RequestUserDeleteMutation,\r\n CancelUserDeleteMutation,\r\n LoginHistoryQuery,\r\n} from './user.gql';\r\nimport { LrApolloService } from '../api/lr-apollo.service';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class UserService {\r\n constructor(private lrApollo: LrApolloService) {}\r\n\r\n async getUserByEmail(email: string): Promise<User> {\r\n return this.getUser({ email });\r\n }\r\n\r\n async getUserByUsername(username: string): Promise<User> {\r\n return this.getUser({ username });\r\n }\r\n\r\n async getUser({ email, username }: GetUserInput): Promise<User> {\r\n const { user } = await this.lrApollo.query<UserQueryType>({\r\n query: UserQuery,\r\n variables: {\r\n email,\r\n username,\r\n },\r\n });\r\n return user;\r\n }\r\n\r\n async requestUserDelete(): Promise<UserDelete> {\r\n const res = await this.lrApollo.mutate<{ requestUserDelete: any }>({\r\n mutation: RequestUserDeleteMutation,\r\n variables: {\r\n input: {},\r\n },\r\n });\r\n\r\n return res.requestUserDelete.userDelete;\r\n }\r\n\r\n async cancelUserDelete(): Promise<string> {\r\n const res = await this.lrApollo.mutate<{ cancelUserDelete: any }>({\r\n mutation: CancelUserDeleteMutation,\r\n variables: {\r\n input: {},\r\n },\r\n });\r\n\r\n return res.cancelUserDelete.id;\r\n }\r\n\r\n async loginHistory(first: number = null, after: string = null): Promise<any> {\r\n // first: return first n entries\r\n // after: pass in the pageInfo.endCursor to paginate\r\n const res = await this.lrApollo.query<{ loginHistory: any }>({\r\n query: LoginHistoryQuery,\r\n variables: {\r\n first,\r\n after,\r\n },\r\n });\r\n\r\n return res.loginHistory;\r\n }\r\n}\r\n","import gql from 'graphql-tag';\r\nimport { FetchKeyGraphField, KeyGraphFragment } from '../_common/queries.gql';\r\n\r\nexport const KeyExchangeFields = `\r\n id\r\n token\r\n state\r\n mode\r\n isInitiator\r\n initiator {\r\n id\r\n username\r\n }\r\n responder {\r\n id\r\n username\r\n }\r\n created\r\n modified\r\n tokenExpiryTime\r\n isExpired\r\n initiatorRootKeyCipher\r\n initiatorActionRequired\r\n responderActionRequired\r\n responderEmailAddress\r\n otk {\r\n state\r\n otKeyParams\r\n otKeyCipher\r\n sharedKey {\r\n id\r\n }\r\n mkSharedKey {\r\n id\r\n }\r\n initiatorSigPxk {\r\n id\r\n }\r\n responderSigPxk {\r\n id\r\n }\r\n initiatorOneTimePbkCipher\r\n responderPbkCipher\r\n}`;\r\n\r\nexport const UserSharedKeyFields = `\r\n userSigPrk {\r\n id\r\n }\r\n otherSigPbk {\r\n id\r\n }\r\n sharedKey {\r\n id\r\n }\r\n mkSharedKey {\r\n id\r\n }\r\n mkPxk {\r\n id\r\n pbk\r\n }\r\n mkReshareRequestCipher\r\n mkReshareResponseCipher\r\n mkReshareRequestSent\r\n mkReshareResponseSent\r\n`;\r\n\r\nexport const CurrentUserSharedKeyQuery = gql`\r\nquery CurrentUserSharedKeyQuery(\r\n $username: String\r\n $userId: LrRelayIdInput\r\n $cachedKeyIds: [LrRelayIdInput!]\r\n) {\r\n currentUserSharedKey(\r\n username: $username\r\n userId: $userId\r\n ) {\r\n userSharedKey {\r\n ${UserSharedKeyFields}\r\n }\r\n }\r\n keyGraph(cachedKeyIds: $cachedKeyIds) {\r\n ...KeyGraphFragment\r\n }\r\n}\r\n${KeyGraphFragment}`;\r\n\r\nexport const KeyExchangesQuery = gql`\r\nquery KeyExchangeQuery(\r\n$orderBy: String\r\n$isExpired: Boolean\r\n$initiatorActionRequired: Boolean\r\n$responderActionRequired: Boolean\r\n$initiator: ID\r\n$responder: ID\r\n$state: String\r\n) {\r\nkeyExchanges(\r\n orderBy: $orderBy\r\n isExpired: $isExpired\r\n initiatorActionRequired: $initiatorActionRequired\r\n responderActionRequired: $responderActionRequired\r\n initiator: $initiator\r\n responder: $responder\r\n state: $state\r\n) {\r\n edges {\r\n node {\r\n ${KeyExchangeFields}\r\n }\r\n }\r\n}\r\nkeyGraph {\r\n ...KeyGraphFragment\r\n}\r\n}\r\n${KeyGraphFragment}\r\n`;\r\n\r\nexport const KeyExchangeQuery = gql`\r\nquery KeyExchangeQuery(\r\n $id: LrRelayIdInput!\r\n) {\r\n keyExchange(\r\n id: $id\r\n ) {\r\n ${KeyExchangeFields}\r\n }\r\n keyGraph {\r\n ...KeyGraphFragment\r\n }\r\n}\r\n${KeyGraphFragment}\r\n`;\r\n\r\n// Key graph is only available for authenticated users. This query\r\n// is for unauthenticated users.\r\nexport const KeyExchangeTokenQuery = gql`\r\nquery KeyExchangeQuery(\r\n $id: LrRelayIdInput!\r\n $token: String\r\n) {\r\n keyExchange(\r\n id: $id\r\n token: $token\r\n ) {\r\n ${KeyExchangeFields}\r\n }\r\n}`;\r\n\r\nexport const InitiateOtkMutation = gql`\r\nmutation InitiateKeyExchangeOtk(\r\n$input: InitiateKeyExchangeOtkInput!\r\n) {\r\ninitiateKeyExchangeOtk(input: $input) {\r\n keyExchange {\r\n ${KeyExchangeFields}\r\n }\r\n}\r\n${FetchKeyGraphField}\r\n}`;\r\n\r\nexport const RespondOtkMutation = gql`\r\nmutation RespondKeyExchangeOtk(\r\n $input: RespondKeyExchangeOtkInput!\r\n) {\r\n respondKeyExchangeOtk(input: $input) {\r\n keyExchange {\r\n ${KeyExchangeFields}\r\n }\r\n userSharedKey {\r\n ${UserSharedKeyFields}\r\n }\r\n tp {\r\n id\r\n }\r\n }\r\n}`;\r\n\r\nexport const CompleteOtkMutation = gql`\r\nmutation CompleteKeyExchangeOtk(\r\n $input: CompleteKeyExchangeOtkInput!\r\n) {\r\n completeKeyExchangeOtk(input: $input) {\r\n keyExchange {\r\n ${KeyExchangeFields}\r\n }\r\n userSharedKey {\r\n ${UserSharedKeyFields}\r\n }\r\n tp {\r\n id\r\n }\r\n }\r\n}`;\r\n","import { Key } from '../cryptography/cryptography.types';\r\nimport { AccessLevel } from '../category/category.types';\r\nimport { JWK } from 'node-jose';\r\nimport { ContactCardName, TrustedPartyDetails } from '../users/profile.types';\r\n\r\n// Will be encrypted using the root key of the initiator\r\nexport interface PlainInitiatorRootKeyCipher {\r\n nonce: string;\r\n oneTimePrk: object; // onetime public encryption key responder use to send data back to initiator\r\n otKey: object;\r\n initiatorContactCard?: {\r\n // Owner only access to this data\r\n plainOwnerCipherDataJson: any;\r\n // Shared read access between owner and receiver. Only the owner has write access.\r\n plainSharedCipherDataJson: any;\r\n };\r\n initiator: {\r\n message?: KeyExchangeMessage;\r\n contactCard?: {\r\n // Shared read access between owner and receiver. Only the owner has write access.\r\n plainSharedCipherDataJson: TrustedPartyDetails;\r\n };\r\n };\r\n}\r\n\r\nexport interface SharedContactCardInput {\r\n plainCipherDataJson?: any;\r\n plainSharedCipherDataJson?: any;\r\n sharedCipherKey?: object;\r\n}\r\n\r\nexport interface PreparedPermissions {\r\n categories?: { categoryId: string; accessLevel: AccessLevel }[];\r\n records?: { recordId: string; accessLevel: AccessLevel }[];\r\n}\r\n\r\nexport interface KeyExchangeMessage {\r\n name?: string;\r\n email?: string;\r\n message?: string;\r\n permissions?: PreparedPermissions;\r\n}\r\n\r\nexport interface PlainOtKeyCipher {\r\n nonce: string;\r\n initiator: {\r\n oneTimePbk: object; // onetime public encryption key responder use to send data back to initiator\r\n pbk: object; // public encryption key\r\n sigPbk: object; // public signing key\r\n profile?: {\r\n username?: string;\r\n };\r\n message?: KeyExchangeMessage;\r\n contactCard?: {\r\n // Shared read access between owner and receiver. Only the owner has write access.\r\n plainSharedCipherDataJson: TrustedPartyDetails;\r\n };\r\n };\r\n}\r\n\r\nexport interface DecryptedOtk {\r\n plainOtKeyCipher: PlainOtKeyCipher;\r\n otKey: JWK.Key; // The one-time key\r\n}\r\n\r\nexport interface PlainInitiatorOneTimePbkCipher {\r\n nonce: string;\r\n sharedKey: object;\r\n mkSharedKey: object;\r\n responder: {\r\n pbk: object;\r\n sigPbk: object;\r\n profile?: {\r\n username?: string;\r\n };\r\n message?: KeyExchangeMessage;\r\n contactCard?: {\r\n plainSharedCipherDataJson: TrustedPartyDetails;\r\n // Note that this is _not_ the same key as the sharedKey. The sharedKey wraps\r\n // this key in the key graph. But because this key has not been entered into\r\n // the key graph then the responder calls the API, we pass the JWK directly here.\r\n sharedCipherKey: object;\r\n };\r\n };\r\n}\r\n\r\nexport enum OtkState {\r\n OTK_INITIATED = 'OTK_INITIATED',\r\n OTK_ACCEPTED = 'OTK_ACCEPTED',\r\n OTK_COMPLETED = 'OTK_COMPLETED',\r\n}\r\n\r\nexport interface KeyExchangeContactCardInput {\r\n // Accessible by the server and initiator. Server side notification emails need to know some\r\n // information about the initiator.\r\n ownerPlainData?: {\r\n name: ContactCardName;\r\n };\r\n // Owner only access to this data\r\n plainOwnerCipherDataJson: any;\r\n // Shared read access between owner and receiver. Only the owner has write access.\r\n plainSharedCipherDataJson: TrustedPartyDetails;\r\n}\r\n\r\nexport interface InitiateOtkInput {\r\n email?: string;\r\n message?: KeyExchangeMessage;\r\n contactCard?: KeyExchangeContactCardInput;\r\n upgrade?: boolean;\r\n}\r\n\r\nexport interface RespondOtkInput {\r\n id: string;\r\n token: string;\r\n decryptedOtk: DecryptedOtk;\r\n message?: KeyExchangeMessage;\r\n initiatorContactCard?: {\r\n plainReceiverCipherDataJson: any;\r\n };\r\n responderContactCard?: KeyExchangeContactCardInput;\r\n}\r\n\r\nexport enum KeyExchangeState {\r\n IN_PROGRESS = 'IN_PROGRESS',\r\n COMPLETED = 'COMPLETED',\r\n DECLINED = 'DECLINED',\r\n CANCELLED = 'CANCELLED',\r\n}\r\n\r\nexport enum KeyExchangeMode {\r\n OTK = 'OTK',\r\n}\r\n\r\nexport interface Otk {\r\n id: string;\r\n state: OtkState;\r\n otKeyParams: string;\r\n otKeyCipher: string;\r\n sharedKey: Key;\r\n mkSharedKey: Key;\r\n initiatorSigPxk: Key;\r\n responderSigPxk: Key;\r\n // Encrypted\r\n initiatorOneTimePbkCipher: string; // single time use public key created by the initiator.\r\n responderPbkCipher?: string; // responderPbk is the long lived Pbk of the responder.\r\n}\r\n\r\nexport interface KeyExchange {\r\n id: string;\r\n state: KeyExchangeState;\r\n mode: KeyExchangeMode;\r\n created: string;\r\n modified: string;\r\n isInitiator: boolean;\r\n initiator: {\r\n id: string;\r\n username: string;\r\n };\r\n responder: {\r\n id: string;\r\n username: string;\r\n };\r\n initiatorActionRequired?: boolean;\r\n responderActionRequired?: boolean;\r\n responderEmailAddress?: string;\r\n token?: string;\r\n tokenExpiryTime?: string;\r\n isExpired?: boolean;\r\n otk?: Otk;\r\n initiatorRootKeyCipher: string;\r\n}\r\n\r\nexport interface DecryptedKeyExchange extends KeyExchange {\r\n decryptedOtk?: DecryptedOtk;\r\n message?: KeyExchangeMessage;\r\n contactCard?: TrustedPartyDetails;\r\n myMessage?: KeyExchangeMessage;\r\n myContactCard?: TrustedPartyDetails;\r\n}\r\n\r\nexport interface GetKeyExchangeOptions {\r\n // The otKey as a raw string. i.e. key.toJSON(true).k\r\n otKeyK?: string;\r\n // User need the token if they have not responded to the key exchange yet.\r\n // Once they've responded (hence proven they have the OOB Key) they become\r\n // the \"responder\" of this exchange, and can access it when signed in.\r\n token?: string;\r\n}\r\n\r\nexport interface RespondOtk {\r\n keyExchange: KeyExchange;\r\n userSharedKey: UserSharedKey;\r\n tp: {\r\n id: string;\r\n };\r\n}\r\n\r\nexport interface CompleteOtk {\r\n keyExchange: KeyExchange;\r\n userSharedKey: UserSharedKey;\r\n tp: {\r\n id: string;\r\n };\r\n}\r\n\r\nexport interface UserSharedKey {\r\n userSigPrk: Key;\r\n sharedKey: Key;\r\n mkSharedKey?: Key;\r\n mkPxk?: Key;\r\n mkReshareRequestCipher?: string;\r\n mkReshareResponseCipher?: string;\r\n mkReshareRequestSent?: boolean;\r\n mkReshareResponseSent?: boolean;\r\n}\r\n\r\nexport interface GetKeyExchangeListOptions {\r\n orderBy?:\r\n | 'created'\r\n | '-created'\r\n | 'modified'\r\n | '-modified'\r\n | 'expiry_time'\r\n | '-expiry_time';\r\n isExpired?: boolean;\r\n initiatorActionRequired?: boolean;\r\n responderActionRequired?: boolean;\r\n initiator?: string;\r\n responder?: string;\r\n state?: 'IN_PROGRESS' | 'COMPLETED' | 'DECLINED' | 'CANCELLED';\r\n}\r\n\r\nexport interface PlainResponderPbkCipher {\r\n otKey: object;\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport { JWK } from 'node-jose';\r\nimport { LifeReadyAuthService } from '../auth/life-ready-auth.service';\r\nimport { KeyGraphResponse } from '../cryptography/cryptography.types';\r\nimport {\r\n EncryptionService,\r\n JoseSerialization,\r\n} from '../cryptography/encryption.service';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport { LrCodeMismatchException } from '../_common/exceptions';\r\nimport { UserService } from './../users/user.service';\r\nimport {\r\n CompleteOtkMutation,\r\n CurrentUserSharedKeyQuery,\r\n InitiateOtkMutation,\r\n KeyExchangeQuery,\r\n KeyExchangesQuery,\r\n KeyExchangeTokenQuery,\r\n RespondOtkMutation,\r\n} from './key-exchange.gql';\r\nimport {\r\n CompleteOtk,\r\n DecryptedKeyExchange,\r\n DecryptedOtk,\r\n GetKeyExchangeListOptions,\r\n GetKeyExchangeOptions,\r\n InitiateOtkInput,\r\n KeyExchange,\r\n OtkState,\r\n PlainInitiatorOneTimePbkCipher,\r\n PlainInitiatorRootKeyCipher,\r\n PlainOtKeyCipher,\r\n PlainResponderPbkCipher,\r\n RespondOtk,\r\n RespondOtkInput,\r\n UserSharedKey,\r\n} from './key-exchange.types';\r\nimport { LrApolloService } from './lr-apollo.service';\r\nimport { KeyFactoryService as KFS } from '../cryptography/key-factory.service';\r\n// Ref: https://stackoverflow.com/questions/59735280/angular-8-moment-error-cannot-call-a-namespace-moment\r\nimport * as moment_ from 'moment';\r\nconst moment = moment_;\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class KeyExchangeService {\r\n private readonly CLIENT_NONCE_LENGTH = 32;\r\n\r\n constructor(\r\n private keyFactory: KFS,\r\n private keyService: KeyService,\r\n private lrApollo: LrApolloService,\r\n private encryptionService: EncryptionService,\r\n private authService: LifeReadyAuthService,\r\n private userService: UserService\r\n ) {}\r\n\r\n public async getKeyExchangeList(\r\n input: GetKeyExchangeListOptions = {}\r\n ): Promise<any> {\r\n const { keyExchanges } = await this.lrApollo.query<{\r\n keyExchanges: any;\r\n keyGraph: KeyGraphResponse;\r\n }>({\r\n query: KeyExchangesQuery,\r\n variables: {\r\n ...input,\r\n },\r\n });\r\n return keyExchanges;\r\n }\r\n\r\n /**\r\n * @param id If the current user can responder the key exchange if they are either the initiator or the receiver.\r\n * @param token If not signed in, or not the initiator or responder, 'token' must be given.\r\n * @param otKeyK Is the raw one-time key (string). If the responder is explicitly specified at time of initiation, then\r\n * it's possible to have the otKey wrapped by the public key of the responder. In which case, the otKeyK is not needed.\r\n */\r\n public async getKeyExchange(\r\n id: string,\r\n { otKeyK, token }: GetKeyExchangeOptions = {}\r\n ): Promise<DecryptedKeyExchange> {\r\n const { keyExchange } = await this.lrApollo.query<{\r\n keyExchange: KeyExchange;\r\n keyGraph: KeyGraphResponse;\r\n }>({\r\n query: token ? KeyExchangeTokenQuery : KeyExchangeQuery,\r\n variables: {\r\n id,\r\n token,\r\n },\r\n });\r\n return await this.decryptKeyExchange(keyExchange, otKeyK);\r\n }\r\n\r\n private async decryptResponseCipher(\r\n otKey: JWK.Key,\r\n otPrk: JWK.Key,\r\n content: any\r\n ): Promise<PlainInitiatorOneTimePbkCipher> {\r\n // The response could be wrapped by the OtK as well as we the OtPrk\r\n try {\r\n content = await this.encryptionService.decrypt(otKey, content);\r\n } catch (error) {\r\n if (error.message !== 'no key found') {\r\n throw error;\r\n }\r\n // Do nothing to support older versions where message is not wrapped with otk.\r\n }\r\n\r\n // The Prk is single-use and only used to send information from the responder back to the initiator.\r\n return await this.encryptionService.decrypt(otPrk, content);\r\n }\r\n\r\n public async decryptKeyExchange(\r\n keyExchange: KeyExchange,\r\n otKeyK?: string\r\n ): Promise<DecryptedKeyExchange> {\r\n if (keyExchange.isInitiator) {\r\n const rootKey = await this.keyService.getCurrentRootKey();\r\n // Decrypt using the root key to get the Prk\r\n const plainInitiatorRootKeyCipher = ((await this.encryptionService.decrypt(\r\n rootKey.jwk,\r\n keyExchange.initiatorRootKeyCipher\r\n )) as unknown) as PlainInitiatorRootKeyCipher;\r\n\r\n const plainInitiatorOneTimePbkCipher = keyExchange.otk\r\n .initiatorOneTimePbkCipher\r\n ? await this.decryptResponseCipher(\r\n await KFS.asKey(plainInitiatorRootKeyCipher.otKey),\r\n await KFS.asKey(plainInitiatorRootKeyCipher.oneTimePrk),\r\n keyExchange.otk.initiatorOneTimePbkCipher\r\n )\r\n : null;\r\n\r\n const responder =\r\n plainInitiatorOneTimePbkCipher &&\r\n plainInitiatorOneTimePbkCipher.responder;\r\n const initiator =\r\n plainInitiatorRootKeyCipher && plainInitiatorRootKeyCipher.initiator;\r\n\r\n return {\r\n ...keyExchange,\r\n message: responder ? responder.message : null,\r\n contactCard:\r\n responder && responder.contactCard\r\n ? responder.contactCard.plainSharedCipherDataJson\r\n : null,\r\n myContactCard:\r\n initiator && initiator.contactCard\r\n ? initiator.contactCard.plainSharedCipherDataJson\r\n : null,\r\n myMessage: initiator && initiator.message,\r\n };\r\n } else {\r\n const decryptedOtk = await this.decryptOtk(keyExchange, otKeyK);\r\n\r\n const initiator = decryptedOtk && decryptedOtk.plainOtKeyCipher.initiator;\r\n\r\n return {\r\n ...keyExchange,\r\n decryptedOtk,\r\n message: initiator && initiator.message,\r\n contactCard:\r\n initiator &&\r\n initiator.contactCard &&\r\n initiator.contactCard.plainSharedCipherDataJson,\r\n };\r\n }\r\n }\r\n\r\n private async decryptOtk(\r\n keyExchange: KeyExchange,\r\n otKeyK?: string\r\n ): Promise<DecryptedOtk> {\r\n const otKey = await this.getOtKey(keyExchange, otKeyK);\r\n\r\n return otKey && keyExchange.otk.otKeyCipher\r\n ? {\r\n plainOtKeyCipher: await this.encryptionService.decrypt(\r\n otKey,\r\n keyExchange.otk.otKeyCipher\r\n ),\r\n otKey,\r\n }\r\n : null;\r\n }\r\n\r\n private async getOtKey(\r\n keyExchange: KeyExchange,\r\n otKeyK?: string\r\n ): Promise<JWK.Key> {\r\n if (otKeyK) {\r\n return await KFS.asKey({\r\n ...JSON.parse(keyExchange.otk.otKeyParams),\r\n k: otKeyK,\r\n });\r\n } else if (\r\n keyExchange.otk.state === OtkState.OTK_INITIATED &&\r\n !keyExchange.isInitiator &&\r\n keyExchange.otk.responderPbkCipher\r\n ) {\r\n // Assuming existing user getting invited where OTK is wrapped in responder's public key.\r\n const prk = await this.keyService.getCurrentPxk();\r\n const decryptedCipher: any = await this.encryptionService.decrypt(\r\n prk.jwk,\r\n JSON.parse(keyExchange.otk.responderPbkCipher),\r\n {\r\n serializations: [JoseSerialization.COMPACT],\r\n }\r\n );\r\n if (decryptedCipher.otKey) {\r\n return await KFS.asKey(decryptedCipher.otKey);\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n async initiateOtk({\r\n message,\r\n email,\r\n contactCard,\r\n upgrade,\r\n }: InitiateOtkInput): Promise<{ keyExchange: KeyExchange; otKeyK: string }> {\r\n const otKey = await this.keyFactory.createKey();\r\n const nonce = this.keyFactory.randomString(this.CLIENT_NONCE_LENGTH);\r\n const user = await this.authService.getUser();\r\n\r\n // New PKC key for encryption. This key is used only once when the responder sends\r\n // back their signing public key.\r\n const initiatorOneTimePrk = await this.keyFactory.createPkcKey();\r\n\r\n // Option 1: New PKC key for signing\r\n // const initiatorSigPrk = await this.keyService.createPkcSignKey();\r\n\r\n // Option 2: Use the user's global signing key.\r\n // This key is used to prove the initiator's identity.\r\n const initiatorPrk = await this.keyService.getCurrentPxk();\r\n const initiatorSigPrk = await this.keyService.getCurrentSigPxk();\r\n\r\n let initiatorPlainDataSig: string = null;\r\n\r\n if (contactCard && contactCard.ownerPlainData) {\r\n initiatorPlainDataSig = JSON.stringify(\r\n await this.encryptionService.sign(\r\n initiatorSigPrk.jwk,\r\n contactCard.ownerPlainData\r\n )\r\n );\r\n }\r\n\r\n const initiator = {\r\n message,\r\n contactCard: contactCard\r\n ? {\r\n plainSharedCipherDataJson: contactCard.plainSharedCipherDataJson,\r\n }\r\n : null,\r\n };\r\n\r\n // Content to be encrypted using the OTK.\r\n const plainOtKeyCipher: PlainOtKeyCipher = {\r\n nonce,\r\n initiator: {\r\n ...initiator,\r\n oneTimePbk: initiatorOneTimePrk.toJSON(), // onetime public encryption key responder use to send data back to initiator\r\n pbk: initiatorPrk.jwk.toJSON(), // public encryption key\r\n sigPbk: initiatorSigPrk.jwk.toJSON(), // public signing key\r\n profile: {\r\n username: user.username,\r\n },\r\n },\r\n };\r\n\r\n const otKeyCipher = await this.encryptionService.encrypt(\r\n otKey,\r\n plainOtKeyCipher\r\n );\r\n\r\n // Content to be encrypted using the initiator's root key.\r\n const plainInitiatorRootKeyCipher: PlainInitiatorRootKeyCipher = {\r\n nonce,\r\n oneTimePrk: initiatorOneTimePrk.toJSON(true),\r\n // Should not need to keep this encrypted since we are using the global signing key.\r\n // sigPrk: initiatorSigPrk.toJSON(true),\r\n\r\n // Save it in case the initiator want to decode the otKeyCipher.\r\n // Since the otKey is only used once, and that otKeyCipher contains only\r\n // the public key of the initiator, it's safe just leave the otKey stored here.\r\n otKey: otKey.toJSON(true),\r\n // These should be storing information such as how the fields of the shared contact card is\r\n // derived from the master contact card.\r\n initiatorContactCard: contactCard,\r\n initiator,\r\n };\r\n\r\n const rootKey = await this.keyService.getCurrentRootKey();\r\n const initiatorRootKeyCipher = await this.encryptionService.encrypt(\r\n rootKey.jwk,\r\n plainInitiatorRootKeyCipher\r\n );\r\n\r\n // The raw OTK\r\n const otKeyK: string = (otKey.toJSON(true) as any).k;\r\n\r\n // API call\r\n const { initiateKeyExchangeOtk } = await this.lrApollo.mutate<any>({\r\n mutation: InitiateOtkMutation,\r\n variables: {\r\n input: {\r\n // These will be stored on the server\r\n initiatorRootKeyCipher: JSON.stringify(initiatorRootKeyCipher),\r\n initiatorPxkId: initiatorPrk.id,\r\n initiatorSigPxkId: initiatorSigPrk.id,\r\n // These will be sent to the responder\r\n otKeyParams: JSON.stringify(otKey.toJSON()),\r\n otKeyCipher: JSON.stringify(otKeyCipher),\r\n sendEmail: email\r\n ? {\r\n email,\r\n rawOtKey: otKeyK,\r\n }\r\n : null,\r\n createTp: true,\r\n initiatorPlainDataSig,\r\n upgrade,\r\n },\r\n },\r\n });\r\n return { keyExchange: initiateKeyExchangeOtk.keyExchange, otKeyK };\r\n }\r\n\r\n async respondOtk({\r\n id,\r\n token,\r\n decryptedOtk,\r\n message,\r\n initiatorContactCard,\r\n responderContactCard: sentContactCard,\r\n }: RespondOtkInput): Promise<RespondOtk> {\r\n const user = await this.authService.getUser();\r\n const rootKey = await this.keyService.getCurrentRootKey();\r\n\r\n const masterKeyId = this.keyService.getCurrentMasterKey().id;\r\n const masterKey = await this.keyService.getCurrentMasterKey();\r\n\r\n const sharedKey = await this.keyFactory.createKey();\r\n const mkSharedKey = await this.keyFactory.createKey();\r\n\r\n const rkWrappedSharedKey = await this.encryptionService.encrypt(\r\n rootKey.jwk,\r\n sharedKey.toJSON(true)\r\n );\r\n const mkWrappedMkSharedKey = await this.encryptionService.encrypt(\r\n masterKey.jwk,\r\n mkSharedKey.toJSON(true)\r\n );\r\n\r\n const initiatorOneTimePbk = await KFS.asKey(\r\n decryptedOtk.plainOtKeyCipher.initiator.oneTimePbk\r\n );\r\n\r\n const initiatorPbk = await KFS.asKey(\r\n decryptedOtk.plainOtKeyCipher.initiator.pbk\r\n );\r\n const initiatorSigPbk = await KFS.asKey(\r\n decryptedOtk.plainOtKeyCipher.initiator.sigPbk\r\n );\r\n\r\n // Option 1: Using new Prk for each TP pair\r\n // Create a new public signing key for the responder.\r\n // const responderSigPrk = await this.keyService.createPkcSignKey()\r\n // const rkWrappedResponderSigPrk = await this.encrypt(rootKey, responderSigPrk.toJSON(true));\r\n\r\n // Option 2: Responder already has a signing Prk\r\n const responderPrk = await this.keyService.getCurrentPxk();\r\n const responderSigPrk = await this.keyService.getCurrentSigPxk();\r\n\r\n const signedInitiatorPbk = await this.encryptionService.sign(\r\n responderSigPrk.jwk,\r\n initiatorPbk.toJSON()\r\n );\r\n const signedInitiatorSigPbk = await this.encryptionService.sign(\r\n responderSigPrk.jwk,\r\n initiatorSigPbk.toJSON()\r\n );\r\n\r\n const plainInitiatorOneTimePbkCipher: PlainInitiatorOneTimePbkCipher = {\r\n nonce: decryptedOtk.plainOtKeyCipher.nonce,\r\n sharedKey: sharedKey.toJSON(true),\r\n mkSharedKey: mkSharedKey.toJSON(true),\r\n responder: {\r\n pbk: responderPrk.jwk.toJSON(), // public key\r\n sigPbk: responderSigPrk.jwk.toJSON(), // public key\r\n profile: {\r\n username: user.username,\r\n },\r\n message,\r\n },\r\n };\r\n\r\n let receivedCardInput;\r\n if (decryptedOtk.plainOtKeyCipher.initiator.contactCard) {\r\n // Set the info about the initiator to be the ones sent by the initiator. We need th responder to do the encryption here\r\n // because the initiator does not have the shared key yet, and we want the responder to have a functional contact card after\r\n // this exchange. The initiator can double check the contact details are correct and sign it when it completes the exchange.\r\n const plainSharedCipherDataJson =\r\n decryptedOtk.plainOtKeyCipher.initiator.contactCard\r\n .plainSharedCipherDataJson;\r\n\r\n // Create keys\r\n const receiverKey = await this.keyFactory.createKey();\r\n const ccSharedKey = await this.keyFactory.createKey();\r\n const sigPxk = await this.keyService.getCurrentSigPxk();\r\n\r\n receivedCardInput = {\r\n receiverWrappedKey: JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n rootKey.jwk,\r\n receiverKey.toJSON(true)\r\n )\r\n ),\r\n receiverWrappingKeyId: rootKey.id,\r\n receiverCipherData: initiatorContactCard\r\n ? JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n receiverKey,\r\n initiatorContactCard.plainReceiverCipherDataJson\r\n )\r\n )\r\n : '',\r\n sharedWrappedKey: JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n sharedKey,\r\n ccSharedKey.toJSON(true)\r\n )\r\n ),\r\n };\r\n\r\n const sharedCipherData = await this.encryptionService.encrypt(\r\n ccSharedKey,\r\n plainSharedCipherDataJson\r\n );\r\n receivedCardInput.sharedCipherDataSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, sharedCipherData)\r\n );\r\n receivedCardInput.sigPxkId = sigPxk.id;\r\n\r\n plainInitiatorOneTimePbkCipher.responder.contactCard = {\r\n ...plainInitiatorOneTimePbkCipher.responder.contactCard,\r\n sharedCipherKey: ccSharedKey.toJSON(true),\r\n };\r\n }\r\n\r\n let sentCardInput;\r\n if (sentContactCard) {\r\n // Create keys\r\n const ownerKey = await this.keyFactory.createKey();\r\n const ccSharedKey = await this.keyFactory.createKey();\r\n const sigPxk = await this.keyService.getCurrentSigPxk();\r\n\r\n sentCardInput = {\r\n ownerWrappedKey: JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n rootKey.jwk,\r\n ownerKey.toJSON(true)\r\n )\r\n ),\r\n ownerWrappingKeyId: rootKey.id,\r\n ownerCipherData: sentContactCard.plainOwnerCipherDataJson\r\n ? JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n ownerKey,\r\n sentContactCard.plainOwnerCipherDataJson\r\n )\r\n )\r\n : '',\r\n\r\n sharedWrappedKey: JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n sharedKey,\r\n ccSharedKey.toJSON(true)\r\n )\r\n ),\r\n };\r\n\r\n const sharedCipherData = await this.encryptionService.encrypt(\r\n ccSharedKey,\r\n sentContactCard.plainSharedCipherDataJson\r\n );\r\n sentCardInput.sharedCipherDataSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, sharedCipherData)\r\n );\r\n sentCardInput.sigPxkId = sigPxk.id;\r\n\r\n if (sentContactCard.ownerPlainData) {\r\n sentCardInput.ownerPlainDataSig = JSON.stringify(\r\n await this.encryptionService.sign(\r\n responderSigPrk.jwk,\r\n sentContactCard.ownerPlainData\r\n )\r\n );\r\n }\r\n\r\n // Contact card info readable by the initiator\r\n plainInitiatorOneTimePbkCipher.responder.contactCard = {\r\n ...plainInitiatorOneTimePbkCipher.responder.contactCard,\r\n plainSharedCipherDataJson: sentContactCard.plainSharedCipherDataJson,\r\n };\r\n }\r\n\r\n // Encrypt with one-time public key\r\n let initiatorOneTimePbkCipher = await this.encryptionService.encrypt(\r\n initiatorOneTimePbk,\r\n plainInitiatorOneTimePbkCipher\r\n );\r\n\r\n // Encrypt with the otk again to keep use of asymmetric keys to a minimum.\r\n initiatorOneTimePbkCipher = await this.encryptionService.encrypt(\r\n decryptedOtk.otKey,\r\n initiatorOneTimePbkCipher\r\n );\r\n\r\n const { respondKeyExchangeOtk } = await this.lrApollo.mutate<any>({\r\n mutation: RespondOtkMutation,\r\n variables: {\r\n input: {\r\n keyExchangeId: id,\r\n keyExchangeToken: token,\r\n rootKeyId: rootKey.id,\r\n masterKeyId,\r\n // These will be stored on the server\r\n responderPxkId: responderPrk.id,\r\n responderSigPxkId: responderSigPrk.id,\r\n signedInitiatorPbk: JSON.stringify(signedInitiatorPbk),\r\n signedInitiatorSigPbk: JSON.stringify(signedInitiatorSigPbk),\r\n // rkWrappedInitiatorSigPbk: JSON.stringify(rkWrappedInitiatorSigPbk),\r\n\r\n // Option 1: Using new Prk for each TP pair\r\n // rkWrappedResponderSigPrk: JSON.stringify(rkWrappedResponderSigPrk),\r\n rkWrappedSharedKey: JSON.stringify(rkWrappedSharedKey),\r\n mkWrappedMkSharedKey: JSON.stringify(mkWrappedMkSharedKey),\r\n // These will be sent to the initiator\r\n initiatorOneTimePbkCipher: JSON.stringify(initiatorOneTimePbkCipher),\r\n initiatorContactCard: receivedCardInput,\r\n responderContactCard: sentCardInput,\r\n },\r\n },\r\n });\r\n\r\n return {\r\n keyExchange: respondKeyExchangeOtk.keyExchange,\r\n userSharedKey: respondKeyExchangeOtk.userSharedKey,\r\n tp: respondKeyExchangeOtk.tp,\r\n };\r\n }\r\n\r\n async completeOtk(\r\n keyExchangeId: string,\r\n initiatorRootKeyCipher: string,\r\n initiatorOneTimePbkCipher: string,\r\n responderContactCard?: string\r\n ): Promise<CompleteOtk> {\r\n const rootKey = await this.keyService.getCurrentRootKey();\r\n const masterKey = await this.keyService.getCurrentMasterKey();\r\n\r\n // Decrypt using the root key to get the Prk\r\n const plainInitiatorRootKeyCipher = ((await this.encryptionService.decrypt(\r\n rootKey.jwk,\r\n initiatorRootKeyCipher\r\n )) as unknown) as PlainInitiatorRootKeyCipher;\r\n\r\n // The Prk is single-use and only used to send information from the responder back to the initiator.\r\n const plainInitiatorOneTimePbkCipher = await this.decryptResponseCipher(\r\n await KFS.asKey(plainInitiatorRootKeyCipher.otKey),\r\n await KFS.asKey(plainInitiatorRootKeyCipher.oneTimePrk),\r\n initiatorOneTimePbkCipher\r\n );\r\n\r\n // Check the nonce match to ensure the responder was the one holding the OTK\r\n if (\r\n plainInitiatorRootKeyCipher.nonce !== plainInitiatorOneTimePbkCipher.nonce\r\n ) {\r\n throw new LrCodeMismatchException(\r\n 'The nonce returned by responder does not match with the one created by the initiator.'\r\n );\r\n }\r\n\r\n // Option 1: Assuming the signing key is unique between users.\r\n // const initiatorSigPrk = await KFS.asKey(ke.plainInitiatorRootKeyCipher.sigPrk);\r\n // const rkWrappedInitiatorSigPrk = await this.encrypt(rootKey, initiatorSigPrk.toJSON(true));\r\n\r\n // Option 2: Use the user's global signing key.\r\n // In this case the initiatorSigPrk is already a part of the key graph.\r\n // So there's nothing to do here.\r\n\r\n // Protected the signing public key of the responder.\r\n const initiatorSigPrk = await this.keyService.getCurrentSigPxk();\r\n const responderSigPbk = await KFS.asKey(\r\n plainInitiatorOneTimePbkCipher.responder.sigPbk\r\n );\r\n const responderPbk = await KFS.asKey(\r\n plainInitiatorOneTimePbkCipher.responder.pbk\r\n );\r\n\r\n const signedResponderPbk = await this.encryptionService.sign(\r\n initiatorSigPrk.jwk,\r\n responderPbk.toJSON()\r\n );\r\n const signedResponderSigPbk = await this.encryptionService.sign(\r\n initiatorSigPrk.jwk,\r\n responderSigPbk.toJSON()\r\n );\r\n\r\n const sharedKey = await KFS.asKey(plainInitiatorOneTimePbkCipher.sharedKey);\r\n const rkWrappedSharedKey = await this.encryptionService.encrypt(\r\n rootKey.jwk,\r\n sharedKey.toJSON(true)\r\n );\r\n\r\n const mkSharedKey = await KFS.asKey(\r\n plainInitiatorOneTimePbkCipher.mkSharedKey\r\n );\r\n const mkWrappedMkSharedKey = await this.encryptionService.encrypt(\r\n masterKey.jwk,\r\n mkSharedKey.toJSON(true)\r\n );\r\n\r\n let responderContactCardCipherInput;\r\n if (responderContactCard) {\r\n // Create key\r\n const receiverKey = await this.keyFactory.createKey();\r\n\r\n responderContactCardCipherInput = {\r\n receiverWrappedKey: JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n rootKey.jwk,\r\n receiverKey.toJSON(true)\r\n )\r\n ),\r\n receiverWrappingKeyId: rootKey.id,\r\n receiverCipherData: JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n receiverKey,\r\n responderContactCard\r\n )\r\n ),\r\n };\r\n }\r\n\r\n // Get the data needed from the initiator's cipher data.\r\n let initiatorContactCardCipherInput;\r\n let initiatorContactCardSharedCipherInput;\r\n if (plainInitiatorRootKeyCipher.initiatorContactCard) {\r\n const initiatorContactCard =\r\n plainInitiatorRootKeyCipher.initiatorContactCard;\r\n const ownerKey = await this.keyFactory.createKey();\r\n const sharedCipherKey = await KFS.asKey(\r\n plainInitiatorOneTimePbkCipher.responder.contactCard.sharedCipherKey\r\n );\r\n\r\n const ownerWrappedKey = JSON.stringify(\r\n await this.encryptionService.encrypt(rootKey.jwk, ownerKey.toJSON(true))\r\n );\r\n const ownerCipherData = initiatorContactCard.plainOwnerCipherDataJson\r\n ? JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n ownerKey,\r\n initiatorContactCard.plainOwnerCipherDataJson\r\n )\r\n )\r\n : '';\r\n\r\n initiatorContactCardCipherInput = {\r\n ownerWrappedKey,\r\n ownerWrappingKeyId: rootKey.id,\r\n ownerCipherData,\r\n };\r\n\r\n initiatorContactCardSharedCipherInput = {\r\n sigPxkId: initiatorSigPrk.id,\r\n };\r\n\r\n const sharedCipherData = await this.encryptionService.encrypt(\r\n sharedCipherKey,\r\n initiatorContactCard.plainSharedCipherDataJson\r\n );\r\n initiatorContactCardSharedCipherInput.sharedCipherDataSig = JSON.stringify(\r\n await this.encryptionService.sign(initiatorSigPrk.jwk, sharedCipherData)\r\n );\r\n }\r\n\r\n // TODO ideally we update the shared data in the contact card sent to the responder as well since that\r\n // CC was created by the responder.\r\n\r\n const res = await this.lrApollo.mutate<any>({\r\n mutation: CompleteOtkMutation,\r\n variables: {\r\n input: {\r\n keyExchangeId,\r\n rootKeyId: rootKey.id,\r\n masterKeyId: masterKey.id,\r\n initiatorSigPxkId: initiatorSigPrk.id,\r\n signedResponderPbk: JSON.stringify(signedResponderPbk),\r\n signedResponderSigPbk: JSON.stringify(signedResponderSigPbk),\r\n rkWrappedSharedKey: JSON.stringify(rkWrappedSharedKey),\r\n mkWrappedMkSharedKey: JSON.stringify(mkWrappedMkSharedKey),\r\n responderContactCardCipher: responderContactCardCipherInput,\r\n initiatorContactCardCipher: initiatorContactCardCipherInput,\r\n initiatorContactCardSharedCipher: initiatorContactCardSharedCipherInput,\r\n },\r\n },\r\n });\r\n return res.completeKeyExchangeOtk;\r\n }\r\n\r\n public async currentUserSharedKey(input: {\r\n username?: string;\r\n userId?: string;\r\n }): Promise<UserSharedKey> {\r\n const { currentUserSharedKey } = await this.lrApollo.query<any>({\r\n query: CurrentUserSharedKeyQuery,\r\n variables: {\r\n username: input.username,\r\n userId: input.userId,\r\n },\r\n });\r\n return currentUserSharedKey.userSharedKey;\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport gql from 'graphql-tag';\r\nimport { JWK } from 'node-jose';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { KeyGraphFragment } from '../_common/queries.gql';\r\nimport { KeyExchangeService } from './key-exchange.service';\r\nimport { LrApolloService } from './lr-apollo.service';\r\nimport { KeyFactoryService as KFS } from '../cryptography/key-factory.service';\r\n\r\nexport const SendMessageMutation = gql`\r\n mutation SendMessage($input: SendMessageInput!) {\r\n sendMessage(input: $input) {\r\n message {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const MessageQuery = gql`\r\n query Message($id: LrRelayIdInput!) {\r\n message(id: $id) {\r\n id\r\n sender {\r\n username\r\n }\r\n receiver {\r\n username\r\n }\r\n plainMessage\r\n signedCipherMessage\r\n sharedKey {\r\n id\r\n }\r\n senderSigPbk {\r\n id\r\n }\r\n }\r\n keyGraph {\r\n ...KeyGraphFragment\r\n }\r\n }\r\n ${KeyGraphFragment}\r\n`;\r\n\r\nexport interface SendMessage {\r\n message: {\r\n id: string;\r\n };\r\n}\r\n\r\nexport interface SendMessageInput {\r\n username?: string;\r\n userId?: string;\r\n plainMessageJson?: any;\r\n plainCipherMessageJson?: any;\r\n}\r\n\r\nexport interface Message {\r\n id: string;\r\n sender: {\r\n id: string;\r\n username: string;\r\n };\r\n receiver: {\r\n id: string;\r\n username: string;\r\n };\r\n plainMessage: string;\r\n plainMessageJson?: any;\r\n signedCipherMessage: string;\r\n plainSignedCipherMessageJson?: any;\r\n senderSigPbk: {\r\n id: string;\r\n };\r\n sharedKey: {\r\n id: string;\r\n };\r\n}\r\n\r\ninterface DecryptMessageOptions {\r\n sharedKey: JWK.Key;\r\n senderSigPbk: JWK.Key;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class MessageService {\r\n private readonly encrypt = this.encryptionService.encrypt.bind(\r\n this.encryptionService\r\n );\r\n private readonly decrypt = this.encryptionService.decrypt.bind(\r\n this.encryptionService\r\n );\r\n private readonly sign = this.encryptionService.sign.bind(\r\n this.encryptionService\r\n );\r\n private readonly verify = this.encryptionService.verify.bind(\r\n this.encryptionService\r\n );\r\n\r\n constructor(\r\n private lrApollo: LrApolloService,\r\n private keyGraph: KeyGraphService,\r\n private encryptionService: EncryptionService,\r\n private keyExchangeService: KeyExchangeService\r\n ) {}\r\n\r\n async sendMessage({\r\n username,\r\n userId,\r\n plainMessageJson,\r\n plainCipherMessageJson,\r\n }: SendMessageInput): Promise<SendMessage> {\r\n const userSharedKey = await this.keyExchangeService.currentUserSharedKey({\r\n username,\r\n userId,\r\n });\r\n\r\n const input: any = {\r\n receiverUsername: username,\r\n receiverId: userId,\r\n sharedKeyId: userSharedKey.sharedKey.id,\r\n senderSigPbkId: userSharedKey.userSigPrk.id,\r\n };\r\n\r\n if (plainCipherMessageJson) {\r\n const sharedKey = await this.keyGraph.getJwkKey(\r\n userSharedKey.sharedKey.id\r\n );\r\n const cipherMessage = await this.encrypt(\r\n sharedKey,\r\n plainCipherMessageJson\r\n );\r\n\r\n const senderSigPrk = await this.keyGraph.getJwkKey(\r\n userSharedKey.userSigPrk.id\r\n );\r\n const signedCipherMessage = await this.sign(senderSigPrk, cipherMessage);\r\n\r\n input.signedCipherMessage = JSON.stringify(signedCipherMessage);\r\n }\r\n\r\n if (plainMessageJson) {\r\n input.plainMessage = JSON.stringify(plainMessageJson);\r\n }\r\n\r\n const res = await this.lrApollo.query<any>({\r\n query: SendMessageMutation,\r\n variables: {\r\n input,\r\n },\r\n });\r\n\r\n return res.sendMessage;\r\n }\r\n\r\n async decryptMessage(\r\n message: Message,\r\n { sharedKey, senderSigPbk }: DecryptMessageOptions\r\n ): Promise<void> {\r\n const signedCipherMessage = await this.verify(\r\n senderSigPbk,\r\n JSON.parse(message.signedCipherMessage)\r\n );\r\n\r\n message.plainSignedCipherMessageJson = await this.decrypt(\r\n sharedKey,\r\n signedCipherMessage\r\n );\r\n }\r\n\r\n async getMessage(id: string): Promise<Message> {\r\n const res = await this.lrApollo.query<any>({\r\n query: MessageQuery,\r\n variables: {\r\n id,\r\n },\r\n });\r\n\r\n this.keyGraph.addKeys(res.keyGraph);\r\n\r\n const message = res.message as Message;\r\n\r\n const sharedKey = await this.keyGraph.getJwkKey(message.sharedKey.id);\r\n\r\n // The sender would be getting the Prk back. The receiver gets the Pbk back.\r\n // But only the Pbk is needed here to verify signature.\r\n // So both sender and receiver can access this message.\r\n const senderSigPbk = await this.keyGraph.getJwkKey(message.senderSigPbk.id);\r\n\r\n // Test bad signature\r\n // senderSigPbk = senderSigPbk.toJSON();\r\n // senderSigPbk.n = \"x\" + senderSigPbk.n.substring(1);\r\n // senderSigPbk = await KFS.asKey(senderSigPbk);\r\n\r\n await this.decryptMessage(message, {\r\n sharedKey,\r\n senderSigPbk,\r\n });\r\n\r\n if (message.plainMessage) {\r\n message.plainMessageJson = JSON.parse(message.plainMessage);\r\n }\r\n\r\n return res.message;\r\n }\r\n}\r\n","import { AuthClass } from '@aws-amplify/auth/lib-esm/Auth';\r\nimport { LifeReadyConfig } from '../life-ready.config';\r\n\r\nexport function handleCognitoCallback<T>(\r\n method: (callback: (err?: Error, result?: T) => void) => void\r\n): Promise<T> {\r\n return new Promise<T>((resolve, reject) =>\r\n method((err, result) => (err ? reject(err) : resolve(result)))\r\n );\r\n}\r\n\r\nexport const awsFetch = (authUrl: string) => {\r\n const fetch = window.fetch;\r\n\r\n return (url, options) => {\r\n const pass = () => fetch(url, options);\r\n\r\n if (!options || !options.headers || !options.headers['X-Amz-Target']) {\r\n return pass();\r\n }\r\n\r\n const operation = options.headers['X-Amz-Target'].split('.');\r\n if (\r\n operation.length < 2 ||\r\n operation[0] !== 'AWSCognitoIdentityProviderService'\r\n ) {\r\n return pass();\r\n }\r\n\r\n const body = JSON.parse(options.body);\r\n\r\n if (body && body.ClientMetadata && body.ClientMetadata.noProxy === 'true') {\r\n return pass();\r\n }\r\n\r\n let custom = false;\r\n\r\n if (operation[1] === 'RespondToAuthChallenge') {\r\n if (body && body.ChallengeName === 'NEW_PASSWORD_REQUIRED') {\r\n return pass();\r\n }\r\n custom = true;\r\n } else if (operation[1] === 'InitiateAuth') {\r\n if (body.AuthFlow === 'REFRESH_TOKEN_AUTH') {\r\n custom = true;\r\n }\r\n }\r\n\r\n if (!custom) {\r\n return pass();\r\n }\r\n\r\n return fetch(`${authUrl}auth/proxy/`, {\r\n ...options,\r\n credentials: 'include',\r\n });\r\n };\r\n};\r\n\r\nexport const configureAmplifyAuth = (\r\n { authUrl: authUrl, userPoolId, userPoolWebClientId }: LifeReadyConfig,\r\n auth: AuthClass\r\n) => {\r\n return () => {\r\n const tokens = userPoolId.split('_');\r\n if (tokens.length < 2) {\r\n throw new Error('userPoolId should have this format: {aws-region}_xxxxx');\r\n }\r\n\r\n window.fetch = awsFetch(authUrl);\r\n\r\n auth.configure({\r\n // REQUIRED - Amazon Cognito Region\r\n region: tokens[0],\r\n // OPTIONAL - Amazon Cognito User Pool ID\r\n userPoolId,\r\n // OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)\r\n userPoolWebClientId,\r\n // OPTIONAL - Enforce user authentication prior to accessing AWS resources or not\r\n mandatorySignIn: false,\r\n });\r\n };\r\n};\r\n","import { LrApolloService } from '../api/lr-apollo.service';\r\nimport { HttpClient } from '@angular/common/http';\r\nimport { Inject, Injectable } from '@angular/core';\r\nimport { AuthClass } from '@aws-amplify/auth/lib-esm/Auth';\r\nimport gql from 'graphql-tag';\r\nimport { JWK } from 'node-jose';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport { LifeReadyConfig, LR_CONFIG } from '../life-ready.config';\r\nimport {\r\n LrException,\r\n LrErrorCode,\r\n LrBadLogicException,\r\n} from '../_common/exceptions';\r\nimport { LifeReadyAuthService } from './life-ready-auth.service';\r\nimport { PasswordService } from './password.service';\r\nimport { Slip39Helper } from 'slip39';\r\nimport { KeyFactoryService as KFS } from '../cryptography/key-factory.service';\r\n\r\ninterface SetPasswordApiResult {\r\n username: string;\r\n idpPassword: string;\r\n setPasswordToken: string;\r\n}\r\n\r\nexport interface SetPasswordParams {\r\n lbopId: string;\r\n newPassword: string;\r\n verifiedToken: string;\r\n masterKeyId: string;\r\n masterKey: JWK.Key;\r\n}\r\n\r\nexport interface VerifyContactParams {\r\n email?: string;\r\n phone?: string;\r\n}\r\n\r\nexport interface VerifyContactResult {\r\n // The claim_id identifies the Email/SMS confirmation\r\n claimId: string;\r\n}\r\n\r\nexport interface ConfirmContactParams {\r\n claimId: string;\r\n vCode: string;\r\n}\r\n\r\nexport interface ConfirmContactResult {\r\n // The token to prove the client had the correct confirmation code.\r\n token: string;\r\n}\r\n\r\nexport interface VerifyParams {\r\n claimId: string;\r\n claimToken: string;\r\n lbop: string;\r\n}\r\n\r\nexport interface VerifyResult {\r\n // userId: string;\r\n lbopId: string;\r\n verifiedToken: string;\r\n masterKeyId: string;\r\n masterKey: JWK.Key;\r\n}\r\n\r\nexport interface ChallengeResult {\r\n challenge: any;\r\n lbops: any;\r\n // userId: string;\r\n}\r\n\r\nexport interface Lbop {\r\n id: string;\r\n partial?: string;\r\n name?: string;\r\n lbopString?: string;\r\n}\r\n\r\nexport interface CreateLbopParams {\r\n name?: string;\r\n}\r\n\r\ninterface CreateLbopQuery {\r\n createLbop: {\r\n lbop: Lbop;\r\n };\r\n}\r\n\r\nexport const CreateLbopQuery = gql`\r\n mutation CreateLbop($input: CreateLbopInput!) {\r\n createLbop(input: $input) {\r\n lbop {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\ninterface DeleteLbopQuery {\r\n deleteLbop: Lbop;\r\n}\r\n\r\nexport const DeleteLbopQuery = gql`\r\n mutation DeleteLbop($input: DeleteLbopInput!) {\r\n deleteLbop(input: $input) {\r\n id\r\n }\r\n }\r\n`;\r\n\r\nexport interface UpdateLbopParams {\r\n id: string;\r\n name: string;\r\n}\r\n\r\ninterface UpdateLbopQuery {\r\n updateLbop: Lbop;\r\n}\r\n\r\nexport const UpdateLbopQuery = gql`\r\n mutation UpdateLbop($input: UpdateLbopInput!) {\r\n updateLbop(input: $input) {\r\n lbop {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const LbopQuery = gql`\r\n query Lbop($id: LrRelayIdInput!) {\r\n lbop(id: $id) {\r\n id\r\n cipherMeta\r\n }\r\n }\r\n`;\r\n\r\ninterface LbopsQuery {\r\n lbops: any;\r\n}\r\n\r\nexport const LbopsQuery = gql`\r\n query Lbops {\r\n lbops {\r\n edges {\r\n node {\r\n id\r\n cipherMeta\r\n }\r\n }\r\n }\r\n }\r\n`;\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class LbopService {\r\n private readonly CLIENT_NONCE_LENGTH = 32;\r\n // There are 1024 words (10 bits), so 25 words should give ~256 bits of entropy.\r\n private readonly LBOP_WORDS = 25;\r\n\r\n constructor(\r\n @Inject(LR_CONFIG) private config: LifeReadyConfig,\r\n private http: HttpClient,\r\n private lrApollo: LrApolloService,\r\n private auth: AuthClass,\r\n private authService: LifeReadyAuthService,\r\n private keyFactory: KFS,\r\n private keyService: KeyService,\r\n private encryptionService: EncryptionService,\r\n private keyGraph: KeyGraphService,\r\n private passwordService: PasswordService\r\n ) {}\r\n\r\n private getPartial(lbopString: string): string {\r\n return lbopString.split(' ')[0];\r\n }\r\n\r\n public async remove(id: string): Promise<string> {\r\n const res = await this.lrApollo.mutate<any>({\r\n mutation: DeleteLbopQuery,\r\n variables: {\r\n input: {\r\n id,\r\n },\r\n },\r\n });\r\n\r\n return res.deleteLbop.id;\r\n }\r\n\r\n public async update({ id, name }: UpdateLbopParams): Promise<Lbop> {\r\n const lbop = await this.get(id);\r\n lbop.name = name;\r\n\r\n const masterKey = await this.keyService.getCurrentMasterKey();\r\n const cipherMeta = await this.encryptionService.encrypt(\r\n masterKey.jwk,\r\n lbop\r\n );\r\n\r\n const res = await this.lrApollo.mutate<UpdateLbopQuery>({\r\n mutation: UpdateLbopQuery,\r\n variables: {\r\n input: {\r\n id,\r\n cipherMeta: JSON.stringify(cipherMeta),\r\n },\r\n },\r\n });\r\n\r\n return res.updateLbop;\r\n }\r\n\r\n public async get(id: string): Promise<Lbop> {\r\n const res = await this.lrApollo.query<any>({\r\n query: LbopQuery,\r\n variables: {\r\n id,\r\n },\r\n });\r\n\r\n const masterKey = await this.keyService.getCurrentMasterKey();\r\n\r\n const plainCipherMeta = await this.encryptionService.decrypt(\r\n masterKey.jwk,\r\n JSON.parse(res.lbop.cipherMeta)\r\n );\r\n\r\n return {\r\n id: res.id,\r\n ...plainCipherMeta,\r\n };\r\n }\r\n\r\n public async list(): Promise<Lbop[]> {\r\n const res = await this.lrApollo.query<LbopsQuery>({\r\n query: LbopsQuery,\r\n });\r\n\r\n const masterKey = await this.keyService.getCurrentMasterKey();\r\n\r\n return Promise.all(\r\n res.lbops.edges.map(async (edge) => {\r\n const plainCipherMeta = await this.encryptionService.decrypt(\r\n masterKey.jwk,\r\n JSON.parse(edge.node.cipherMeta)\r\n );\r\n return {\r\n id: edge.node.id,\r\n ...plainCipherMeta,\r\n };\r\n })\r\n );\r\n }\r\n\r\n public async create({ name }: CreateLbopParams): Promise<Lbop> {\r\n if (Slip39Helper.WORD_LIST.length !== 1024) {\r\n throw new LrBadLogicException('Slip39Helper.WORD_LIST.length != 1024');\r\n }\r\n\r\n // Get existing to make sure there are not duplicate first words\r\n const lbops = await this.list();\r\n\r\n // Generate new one\r\n let lbopString;\r\n while (true) {\r\n lbopString = this.keyFactory\r\n .randomChoices(Slip39Helper.WORD_LIST, this.LBOP_WORDS)\r\n .join(' ');\r\n const partial = this.getPartial(lbopString);\r\n\r\n if (!lbops.some((lbop) => lbop.partial === partial)) {\r\n break;\r\n }\r\n }\r\n\r\n const lbopKeyParams = await this.keyFactory.createLbopKeyParams();\r\n const lbopKey = (\r\n await this.keyFactory.deriveLbopKey({\r\n password: lbopString,\r\n ...lbopKeyParams,\r\n })\r\n ).jwk;\r\n\r\n const lbopKeyVerifier = await this.keyFactory.createSignKey();\r\n const wrappedLbopKeyVerifier = await this.encryptionService.encrypt(\r\n lbopKey,\r\n lbopKeyVerifier.toJSON(true)\r\n );\r\n\r\n // Re-encrypt master key with new key\r\n const currentUser = await this.authService.getUser();\r\n const masterKey = await this.keyGraph.getKey(\r\n currentUser.currentUserKey.masterKey.id\r\n );\r\n const wrappedMasterKey = await this.encryptionService.encrypt(\r\n lbopKey,\r\n masterKey.jwk.toJSON(true)\r\n );\r\n\r\n const meta = {\r\n ...(name && { name }),\r\n partial: this.getPartial(lbopString),\r\n };\r\n const cipherMeta = await this.encryptionService.encrypt(\r\n masterKey.jwk,\r\n meta\r\n );\r\n\r\n const res = await this.lrApollo.mutate<CreateLbopQuery>({\r\n mutation: CreateLbopQuery,\r\n variables: {\r\n input: {\r\n cipherMeta: JSON.stringify(cipherMeta),\r\n lbopKeyParams: JSON.stringify(lbopKeyParams),\r\n lbopKeyVerifier: JSON.stringify(lbopKeyVerifier.toJSON(true)),\r\n wrappedLbopKeyVerifier: JSON.stringify(wrappedLbopKeyVerifier),\r\n masterKeyId: currentUser.currentUserKey.masterKey.id,\r\n wrappedMasterKey: JSON.stringify(wrappedMasterKey),\r\n },\r\n },\r\n });\r\n\r\n return {\r\n ...res.createLbop.lbop,\r\n lbopString,\r\n };\r\n }\r\n\r\n // --------------------------------------------------------------------------------------------------------------------\r\n // --------------------------------------------------------------------------------------------------------------------\r\n // Flow below are for password reset via LBOP\r\n //\r\n // --Potential Failure Point xxx--\r\n //\r\n // Look for the above and you can test by interrupting at these points.\r\n //\r\n // The LBOP reset process can be restarted at any point before the call to \"set-password/\". Once \"set-password/\" has been\r\n // called, we assume the client has a short period of time to change the Idp password to the one they've chosen. The \"set-password/\"\r\n // will set the Idp password to a temporary random password. The user can no longer login using their current password. If the Idp\r\n // password change process does not complete or takes longer than the lockout period, the account will not be accessible and a new\r\n // LBOP password reset must be carried out.\r\n // --------------------------------------------------------------------------------------------------------------------\r\n // --------------------------------------------------------------------------------------------------------------------\r\n private async verifyLbops(\r\n challengeResult: ChallengeResult,\r\n lbopString: string\r\n ): Promise<{ lbop: any; signedChallenge: any; lbopKey: JWK.Key }> {\r\n const clientNonce = this.keyFactory.randomString(this.CLIENT_NONCE_LENGTH);\r\n\r\n for (const lbop of challengeResult.lbops) {\r\n const lbopKey = (\r\n await this.keyFactory.deriveLbopKey({\r\n password: lbopString,\r\n ...lbop.lbopKeyParams,\r\n })\r\n ).jwk;\r\n\r\n // If decoding successful then it's the correct lbop\r\n try {\r\n const lbopKeyVerifier = (await this.encryptionService.decrypt(\r\n lbopKey,\r\n lbop.wrappedLbopKeyVerifier\r\n )) as any;\r\n\r\n // Force a bad signature.\r\n // const serverNonce = challengeResult.challenge.serverNonce + \"1\",\r\n\r\n const serverNonce = challengeResult.challenge.serverNonce;\r\n\r\n const signedChallenge = await this.encryptionService.sign(\r\n lbopKeyVerifier,\r\n {\r\n serverNonce,\r\n clientNonce,\r\n }\r\n );\r\n\r\n return {\r\n lbop,\r\n signedChallenge,\r\n lbopKey,\r\n };\r\n } catch (error) {\r\n continue;\r\n }\r\n }\r\n throw new LrException({\r\n source: 'LBOP',\r\n code: 'INVALID_PASSPHRASE',\r\n message: 'Invalid passphrase.',\r\n });\r\n }\r\n\r\n public async verifyContact(\r\n params: VerifyContactParams\r\n ): Promise<VerifyContactResult> {\r\n const ret = this.http\r\n .post<VerifyContactResult>(\r\n `${this.config.authUrl}users/lbop-reset/verify-contact/`,\r\n params\r\n )\r\n .toPromise();\r\n\r\n // --Potential Failure Point 1 --\r\n // The contact verifications are throttled. But otherwise harmless.\r\n\r\n return ret;\r\n }\r\n\r\n public async confirmContact(\r\n params: ConfirmContactParams\r\n ): Promise<ConfirmContactResult> {\r\n return this.http\r\n .post<ConfirmContactResult>(`${this.config.authUrl}cove/respond/`, {\r\n claim_id: params.claimId,\r\n v_code: params.vCode,\r\n })\r\n .toPromise();\r\n\r\n // --Potential Failure Point 2 --\r\n // A verified claim for a contact does not prevent new ones from being generated. So it should be fine to just start again.\r\n }\r\n\r\n public async verify(params: VerifyParams): Promise<VerifyResult> {\r\n const challengeResult = await this.http\r\n .post<ChallengeResult>(\r\n `${this.config.authUrl}users/lbop-reset/get-challenge/`,\r\n {\r\n claimId: params.claimId,\r\n claimToken: params.claimToken,\r\n }\r\n )\r\n .toPromise();\r\n\r\n // --Potential Failure Point 3 --\r\n // This does not lock anything. A second call to \"get-challenge/\" will create a new challenge amd invalidate the first one.\r\n const { signedChallenge, lbop, lbopKey } = await this.verifyLbops(\r\n challengeResult,\r\n params.lbop\r\n );\r\n\r\n const res = await this.http\r\n .post<any>(`${this.config.authUrl}users/lbop-reset/verify-challenge/`, {\r\n lbopId: lbop.lbopId,\r\n signedChallenge,\r\n })\r\n .toPromise();\r\n\r\n // --Potential Failure Point 4 --\r\n // This does not lock anything. So ok to restart.\r\n\r\n return {\r\n lbopId: lbop.lbopId,\r\n verifiedToken: res.verifiedToken,\r\n masterKeyId: res.masterKeyId,\r\n masterKey: await KFS.asKey(\r\n await this.encryptionService.decrypt(lbopKey, res.wrappedMasterKey)\r\n ),\r\n };\r\n }\r\n\r\n public async setPassword(params: SetPasswordParams): Promise<any> {\r\n // Generate the new password derived keys\r\n const passKeyBundle = await this.passwordService.createPassKeyBundle(\r\n params.newPassword\r\n );\r\n\r\n // Re-encrypt master key with new key\r\n const newWrappedMasterKey = await this.encryptionService.encrypt(\r\n passKeyBundle.passKey,\r\n params.masterKey.toJSON(true)\r\n );\r\n\r\n const result = await this.http\r\n .post<SetPasswordApiResult>(\r\n `${this.config.authUrl}users/lbop-reset/set-password/`,\r\n {\r\n lbopId: params.lbopId,\r\n verifiedToken: params.verifiedToken,\r\n masterKeyId: params.masterKeyId,\r\n newWrappedMasterKey,\r\n newPassKey: {\r\n passKeyParams: passKeyBundle.passKeyParams,\r\n passIdpParams: passKeyBundle.passIdpParams,\r\n passIdpVerifierPbk: passKeyBundle.passIdpVerifier.toJSON(),\r\n wrappedPassIdpVerifierPrk: passKeyBundle.wrappedPassIdpVerifierPrk,\r\n },\r\n }\r\n )\r\n .toPromise();\r\n\r\n // --Potential Failure Point 5 --\r\n // A timed mutex is locked. The Idp password change must occur within a period of time.\r\n // If interrupted here, the user can not login with their old password again. They must\r\n // start the whole LBOP password reset process again.\r\n\r\n // This call will go through the LR proxy which is OK since the LR server knows\r\n // the temporary password anyway.\r\n let user = await this.auth.signIn(result.username, result.idpPassword, {\r\n noProxy: 'true',\r\n });\r\n\r\n if (user.challengeName !== 'NEW_PASSWORD_REQUIRED') {\r\n throw new LrException({\r\n message:\r\n 'Internal error. Expecting Cognito to have done a password reset.',\r\n });\r\n }\r\n\r\n // --Potential Failure Point 6 --\r\n // Must restart the LBOP password reset process again.\r\n\r\n // Set new password on Idp\r\n user = await this.auth.completeNewPassword(\r\n user,\r\n this.passwordService.getPassIdpString(passKeyBundle.passIdp),\r\n {}\r\n );\r\n\r\n // --Potential Failure Point 7 --\r\n // Must restart the LBOP password reset process again.\r\n\r\n await this.auth.signOut();\r\n\r\n return await this.http\r\n .post<any>(`${this.config.authUrl}users/lbop-reset/complete/`, {\r\n lbopId: params.lbopId,\r\n setPasswordToken: result.setPasswordToken,\r\n })\r\n .toPromise();\r\n }\r\n}\r\n","import { HttpClient } from '@angular/common/http';\r\nimport { Inject, Injectable } from '@angular/core';\r\nimport { AuthClass } from '@aws-amplify/auth/lib-esm/Auth';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { KeyFactoryService } from '../cryptography/key-factory.service';\r\nimport { LifeReadyConfig, LR_CONFIG } from '../life-ready.config';\r\nimport { PasswordService } from './password.service';\r\nimport { RegisterResult } from './auth.types';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class RegisterService {\r\n constructor(\r\n @Inject(LR_CONFIG) private config: LifeReadyConfig,\r\n private auth: AuthClass,\r\n private http: HttpClient,\r\n private keyFactory: KeyFactoryService,\r\n private encryptionService: EncryptionService,\r\n private passwordService: PasswordService\r\n ) {}\r\n\r\n /**\r\n * Request a verification code to be sent out to an email.\r\n * @return Info needed to be submitted along with the verification code\r\n */\r\n public async verifyEmail(email: string): Promise<string> {\r\n const { claim_id } = await this.http\r\n .post<{ claim_id }>(`${this.config.authUrl}cove/claim/email/`, {\r\n address: email,\r\n context: 'signup',\r\n })\r\n .toPromise();\r\n return claim_id;\r\n }\r\n\r\n public async verifyPhone(phoneNumber: string): Promise<string> {\r\n const { claim_id } = await this.http\r\n .post<{ claim_id }>(`${this.config.authUrl}cove/claim/sms/`, {\r\n address: phoneNumber,\r\n context: 'signup',\r\n })\r\n .toPromise();\r\n return claim_id;\r\n }\r\n\r\n public async confirmVerificationCode(\r\n verificationId: string,\r\n verificationCode: string\r\n ): Promise<string> {\r\n const { token } = await this.http\r\n .post<{ token }>(`${this.config.authUrl}cove/respond/`, {\r\n claim_id: verificationId,\r\n v_code: verificationCode,\r\n })\r\n .toPromise();\r\n return token;\r\n }\r\n\r\n public async register(\r\n email: string,\r\n password: string,\r\n verificationId: string,\r\n verificationToken: string,\r\n verificationType: 'email' | 'phone' = 'email'\r\n ): Promise<RegisterResult> {\r\n // Generate the key material needed for PassIdp which will be the password used for Cognito.\r\n const passKeyBundle = await this.passwordService.createPassKeyBundle(\r\n password\r\n );\r\n\r\n const masterKey = await this.keyFactory.createKey();\r\n const wrappedMasterKey = await this.encryptionService.encrypt(\r\n passKeyBundle.passKey,\r\n masterKey.toJSON(true)\r\n );\r\n\r\n const rootKey = await this.keyFactory.createKey();\r\n const wrappedRootKey = await this.encryptionService.encrypt(\r\n masterKey,\r\n rootKey.toJSON(true)\r\n );\r\n\r\n // Encryption PKC key\r\n const prk = await this.keyFactory.createPkcKey();\r\n const wrappedPrk = await this.encryptionService.encrypt(\r\n rootKey,\r\n prk.toJSON(true)\r\n );\r\n\r\n // Signing PKC key\r\n const sigPrk = await this.keyFactory.createPkcSignKey();\r\n const wrappedSigPrk = await this.encryptionService.encrypt(\r\n rootKey,\r\n sigPrk.toJSON(true)\r\n );\r\n\r\n // API call to setup profile\r\n const user = await this.http\r\n .post<any>(`${this.config.authUrl}users/`, {\r\n claims: [\r\n {\r\n type: verificationType,\r\n token: verificationToken,\r\n claim_id: verificationId,\r\n },\r\n ],\r\n pass_idp_params: passKeyBundle.passIdpParams,\r\n pass_idp_verifier_pbk: passKeyBundle.passIdpVerifier.toJSON(),\r\n wrapped_pass_idp_verifier_prk: passKeyBundle.wrappedPassIdpVerifierPrk,\r\n pass_key_params: passKeyBundle.passKeyParams,\r\n wrapped_master_key: wrappedMasterKey,\r\n wrapped_root_key: wrappedRootKey,\r\n pbk: prk.toJSON(), // public encryption key\r\n wrapped_prk: wrappedPrk,\r\n sig_pbk: sigPrk.toJSON(), // public signing key\r\n wrapped_sig_prk: wrappedSigPrk,\r\n })\r\n .toPromise();\r\n\r\n // API call to create user on cognito\r\n const attributes = {};\r\n user.claims.forEach((claim) => {\r\n attributes[claim.type] = claim.value;\r\n });\r\n\r\n // Random suffix for uniqueness. If there's a duplicate, then used just needs to\r\n // sign up again. But chances of collision is low.\r\n const suffix = this.keyFactory.randomDigitsNoZeros(4);\r\n\r\n const cognitoUser = await this.auth.signUp({\r\n username: `${email.split('@')[0]}.${suffix}`,\r\n password: this.passwordService.getPassIdpString(passKeyBundle.passIdp),\r\n attributes,\r\n // Unfortunately, validationData is not passed to the post\r\n // confirmation cognito trigger. So can can't do the association there.\r\n // The current workflow will create a new user on LR before signing up\r\n // with Cognito. Then Cognito can use the user.id and user.pre_sign_up_token to\r\n // do the validation of the attributes.\r\n // validationData: [\r\n // new CognitoUserAttribute({\r\n // Name: \"user_id\",\r\n // Value: String(user.id)\r\n // }),\r\n // new CognitoUserAttribute({\r\n // Name: \"user_pre_sign_up_token\",\r\n // Value: user.pre_sign_up_token\r\n // })\r\n // ]\r\n clientMetadata: {\r\n user_id: String(user.id),\r\n user_pre_sign_up_token: String(user.pre_sign_up_token),\r\n },\r\n });\r\n\r\n return {\r\n username: cognitoUser.user.getUsername(),\r\n userId: user.id,\r\n preSignUpToken: user.pre_sign_up_token,\r\n userSub: cognitoUser.userSub,\r\n };\r\n }\r\n\r\n public async hibpBreachedAccounts(account: string): Promise<any> {\r\n // The account is just the email\r\n try {\r\n const response = await this.http\r\n .get(\r\n `${this.config.authUrl}users/hibp/breachedaccount/${account}/?truncateResponse=false`\r\n )\r\n .toPromise();\r\n return response;\r\n } catch (error) {\r\n if (error.status === 404) {\r\n return null;\r\n } else {\r\n throw error;\r\n }\r\n }\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport { CognitoUser } from '@aws-amplify/auth';\r\nimport { AuthClass } from '@aws-amplify/auth/lib-esm/Auth';\r\nimport { LrBadArgumentException } from '../_common/exceptions';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class TwoFactorService {\r\n constructor(private auth: AuthClass) {}\r\n\r\n public async getPreferredMFA(): Promise<string> {\r\n const cognitoUser: CognitoUser = await this.auth.currentAuthenticatedUser();\r\n\r\n return await this.auth.getPreferredMFA(cognitoUser);\r\n }\r\n\r\n public async setPreferredMFA(\r\n method: 'TOTP' | 'SMS' | 'NOMFA'\r\n ): Promise<void> {\r\n const cognitoUser: CognitoUser = await this.auth.currentAuthenticatedUser();\r\n\r\n await this.auth.setPreferredMFA(cognitoUser, method);\r\n }\r\n\r\n public async setPhoneNumber(phone): Promise<void> {\r\n const cognitoUser: CognitoUser = await this.auth.currentAuthenticatedUser();\r\n\r\n await this.auth.updateUserAttributes(cognitoUser, {\r\n phone_number: phone,\r\n });\r\n }\r\n\r\n public async getSMSCode() {\r\n await this.auth.verifyCurrentUserAttribute('phone_number');\r\n }\r\n\r\n public async verifySMSCode(verificationCode: string) {\r\n await this.auth.verifyCurrentUserAttributeSubmit(\r\n 'phone_number',\r\n verificationCode\r\n );\r\n }\r\n\r\n public async getSoftwareToken(): Promise<{ code: string; codeUri: string }> {\r\n const [cognitoUser, userInfo] = await Promise.all([\r\n this.auth.currentAuthenticatedUser(),\r\n this.auth.currentUserInfo(),\r\n ]);\r\n\r\n const code = await this.auth.setupTOTP(cognitoUser);\r\n\r\n const email = userInfo.attributes.email;\r\n if (!email) {\r\n throw new LrBadArgumentException('No email associated with user.');\r\n }\r\n\r\n return {\r\n code,\r\n codeUri: `otpauth://totp/${email}?secret=${code}&issuer=LifeReady`,\r\n };\r\n }\r\n\r\n public async verifySoftwareToken(totpCode: string): Promise<void> {\r\n const cognitoUser: CognitoUser = await this.auth.currentAuthenticatedUser();\r\n\r\n await this.auth.verifyTotpToken(cognitoUser, totpCode);\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport { Slip39, Slip39Helper } from 'slip39';\r\n\r\nexport class SecretShare {\r\n constructor(\r\n public assembly: number = 0,\r\n public subAssembly: number = 0,\r\n public mnemonics: string = ''\r\n ) {}\r\n}\r\n\r\nexport class SubAssembly {\r\n constructor(\r\n public index: number,\r\n public threshold: number = 0,\r\n public size: number = 0\r\n ) {\r\n this.clearShares();\r\n }\r\n\r\n shares: SecretShare[];\r\n\r\n public clearShares() {\r\n this.shares = Array();\r\n }\r\n\r\n public addShare(share: SecretShare) {\r\n this.shares.push(share);\r\n }\r\n}\r\n\r\nexport class Assembly {\r\n constructor(public threshold: number = 0) {\r\n this.clearSubAssemblies();\r\n }\r\n\r\n subAssemblies: SubAssembly[];\r\n\r\n public size() {\r\n return this.subAssemblies.length;\r\n }\r\n\r\n public clearSubAssemblies() {\r\n this.subAssemblies = new Array();\r\n }\r\n\r\n public addSubAssembly(subAssembly: SubAssembly) {\r\n this.subAssemblies.push(subAssembly);\r\n }\r\n}\r\n\r\nexport class SubQuorum {\r\n shares: string[];\r\n\r\n constructor(public subAssemblyIndex: number) {\r\n this.clearShares();\r\n }\r\n\r\n public clearShares() {\r\n this.shares = new Array();\r\n }\r\n\r\n public addShare(share: string) {\r\n this.shares.push(share);\r\n }\r\n}\r\n\r\nexport class Quorum {\r\n subQuora: SubQuorum[];\r\n\r\n constructor() {\r\n this.clearSubQuora();\r\n }\r\n\r\n public clearSubQuora() {\r\n this.subQuora = new Array();\r\n }\r\n\r\n public addSubQuorum(subQuorum: SubQuorum) {\r\n this.subQuora.push(subQuorum);\r\n }\r\n\r\n public serialiseShares() {\r\n let shares = [];\r\n\r\n this.subQuora.forEach((subQuorum) => {\r\n shares = shares.concat(subQuorum.shares);\r\n });\r\n\r\n return shares;\r\n }\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class Slip39Service {\r\n constructor() {}\r\n\r\n public async generateShares(secret, passphrase: string, assembly: Assembly) {\r\n // Hex-encode secret.\r\n let ems = btoa(secret);\r\n ems = Slip39Helper.slip39EncodeHex(ems);\r\n\r\n // Construct group specifications\r\n const groups = [];\r\n\r\n for (const sa of assembly.subAssemblies) {\r\n groups.push([sa.threshold, sa.size]);\r\n }\r\n\r\n // Split!\r\n const slip = await Slip39.fromArray(ems, {\r\n passphrase,\r\n threshold: assembly.threshold,\r\n groups,\r\n title: '',\r\n });\r\n\r\n // Extract shares\r\n assembly.subAssemblies.forEach((sa, isa) => {\r\n // Remove any existing shares\r\n sa.clearShares();\r\n\r\n for (let im = 0; im < sa.size; im++) {\r\n // Construct the path to the share, formatted as \"r/<subassembly index>/<member index>\"\r\n // with <subassembly index> and <member index> being two-digit, zero-padded integers.\r\n const path =\r\n 'r/' +\r\n isa.toString().padStart(2, '0') +\r\n '/' +\r\n im.toString().padStart(2, '0');\r\n const mnemonics = slip.fromPath(path).mnemonics[0];\r\n const share = new SecretShare(isa, im, mnemonics);\r\n\r\n sa.addShare(share);\r\n }\r\n });\r\n }\r\n\r\n // Remove all redundant shares. i.e. keep only enough members and groups to satisfy the thresholds.\r\n private minimalSet(mnemonics: string[]): string[] {\r\n // Decode the mnemonics and sort then into groups.\r\n let groupThresh = null;\r\n const groups = new Map();\r\n for (const mnemonic of mnemonics) {\r\n const decoded = Slip39Helper.decodeMnemonic(mnemonic);\r\n\r\n if (groupThresh && groupThresh !== decoded.groupThreshold) {\r\n throw new Error('groupThreshold is different in mnemonics');\r\n }\r\n\r\n groupThresh = decoded.groupThreshold;\r\n\r\n // Note that Slip39.recoverSecret() will do all the error checking again. So it's not critical\r\n // that we error check here. So we just optimistically assume it's all good.\r\n let g = groups.get(decoded.groupIndex);\r\n if (g == null) {\r\n g = {\r\n memberThreshold: decoded.memberThreshold,\r\n members: [],\r\n };\r\n groups.set(decoded.groupIndex, g);\r\n }\r\n\r\n g.members.push({\r\n mnemonic,\r\n decoded,\r\n });\r\n }\r\n\r\n // Keep the minimum set of groups that meet threshold.\r\n const mnemonicsMinSet = [];\r\n let groupCount = 0;\r\n for (const g of groups.values()) {\r\n // Keep only groups that meet threshold\r\n if (g.members.length < g.memberThreshold) {\r\n continue;\r\n }\r\n\r\n // Keep minimum number of approvals needed for group\r\n g.members.slice(0, g.memberThreshold).forEach((member) => {\r\n mnemonicsMinSet.push(member.mnemonic);\r\n });\r\n\r\n ++groupCount;\r\n if (groupCount >= groupThresh) {\r\n break;\r\n }\r\n }\r\n\r\n return mnemonicsMinSet;\r\n }\r\n\r\n public async recoverSecret(shares: string[], passphrase: string) {\r\n shares = this.minimalSet(shares);\r\n\r\n const recovered = await Slip39.recoverSecret(shares, passphrase);\r\n\r\n const secret = Slip39Helper.slip39DecodeHex(recovered);\r\n\r\n return atob(secret);\r\n }\r\n}\r\n","import gql from 'graphql-tag';\r\nimport { KeyGraphFragment } from '../_common/queries.gql';\r\nimport {\r\n DEFAULT_BREADCRUMB_DEPTH,\r\n parentCategoriesField,\r\n AccessFields,\r\n} from '../category/category.gql';\r\n\r\nexport enum FileType {\r\n RecordContent = 'record-content',\r\n RecordAttachment = 'record-attachment',\r\n}\r\n\r\nexport const RecordContentFilter = JSON.stringify({\r\n filter: [\r\n {\r\n contains: {\r\n fileType: FileType.RecordContent,\r\n },\r\n },\r\n ],\r\n});\r\n\r\nexport const RecordAttachmentFilter = JSON.stringify({\r\n filter: [\r\n {\r\n contains: {\r\n fileType: FileType.RecordAttachment,\r\n },\r\n },\r\n ],\r\n});\r\n\r\nexport const GetRecordQuery = (depth = DEFAULT_BREADCRUMB_DEPTH) => gql`\r\nquery Record(\r\n $id: LrRelayIdInput!,\r\n $cachedKeyIds: [LrRelayIdInput!],\r\n $categoryFilter: LrJSONFilter,\r\n $contentFilter: LrJSONFilter,\r\n $attachmentsFilter: LrJSONFilter,\r\n) {\r\n record: directory(id: $id) {\r\n id\r\n keyId\r\n archived\r\n plainMeta\r\n cipherMeta\r\n created\r\n modified\r\n ${AccessFields}\r\n ${parentCategoriesField(depth)}\r\n content: childFileLinks(plainMeta: $contentFilter) {\r\n edges {\r\n node {\r\n childFile {\r\n id\r\n keyId\r\n archived\r\n currentVersion {\r\n state {\r\n id\r\n keyId\r\n plainMeta\r\n cipherMeta\r\n created\r\n modified\r\n }\r\n }\r\n versions {\r\n edges {\r\n node {\r\n operation\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n attachments: childFileLinks(plainMeta: $attachmentsFilter) {\r\n edges {\r\n node {\r\n childFile {\r\n id\r\n keyId\r\n archived\r\n currentVersion {\r\n state {\r\n id\r\n keyId\r\n plainMeta\r\n cipherMeta\r\n contentResource\r\n }\r\n }\r\n versions {\r\n edges {\r\n node {\r\n operation\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n keyGraph(cachedKeyIds: $cachedKeyIds) {\r\n ...KeyGraphFragment\r\n }\r\n}\r\n${KeyGraphFragment}\r\n`;\r\n\r\nexport const CreateRecordContainerMutation = gql`\r\n mutation CreateRecordContainer(\r\n $plainMeta: LrJSONString\r\n $cipherMeta: String\r\n $parentDirectories: [ParentDirectoryInput!]\r\n $parentRootDirectory: ParentRootDirectoryInput\r\n ) {\r\n new: createDirectory(\r\n input: {\r\n plainMeta: $plainMeta\r\n cipherMeta: $cipherMeta\r\n parentDirectories: $parentDirectories\r\n parentRootDirectory: $parentRootDirectory\r\n }\r\n ) {\r\n category: directory {\r\n id\r\n keyId\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const CreateRecordMutation = gql`\r\n mutation CreateFile($input: CreateFileInput!) {\r\n createFile(input: $input) {\r\n file {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UpdateRecordContainerMutation = gql`\r\n mutation UpdateRecord($input: UpdateDirectoryInput!) {\r\n updateDirectory(input: $input) {\r\n directory {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UpdateRecordMutation = gql`\r\n mutation UpdateFile($input: UpdateFileInput!) {\r\n updateFile(input: $input) {\r\n file {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const DeleteRecordMutation = gql`\r\n mutation DeleteRecord($recordId: LrRelayIdInput!) {\r\n deleteDirectory(input: { directoryId: $recordId }) {\r\n id\r\n }\r\n }\r\n`;\r\n\r\nexport const CreateFileMutation = gql`\r\n mutation CreateFile($input: CreateFileInput!) {\r\n createFile(input: $input) {\r\n file {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const DeleteFileMutation = gql`\r\n mutation DeleteFile($fileId: LrRelayIdInput!) {\r\n deleteFile(input: { fileId: $fileId }) {\r\n id\r\n }\r\n }\r\n`;\r\n","export enum AccessLevel {\r\n Owner = 'OWNER',\r\n Admin = 'ADMIN',\r\n Writer = 'WRITER',\r\n Reader = 'READER',\r\n Deny = 'DENY',\r\n}\r\n\r\nexport class SharedAccess {\r\n trustedPartyId: string;\r\n accessLevel: AccessLevel;\r\n isInherited: boolean;\r\n inheritedFrom?: string;\r\n}\r\n\r\nexport class DefaultCategory {\r\n code: string;\r\n name: string;\r\n allowRecords: boolean;\r\n allowCustomCategories: boolean;\r\n archived: boolean;\r\n subCategories?: DefaultCategory[];\r\n}\r\n\r\nexport class VaultRecordType {\r\n id: string;\r\n name: string;\r\n}\r\n\r\nexport class VaultRecord {\r\n id: string;\r\n keyId: string;\r\n name: string;\r\n recordType: VaultRecordType;\r\n createdOn: string | Date;\r\n lastModified: string | Date;\r\n isArchived: boolean;\r\n myAccessLevel: AccessLevel;\r\n sharedAccess: SharedAccess[];\r\n}\r\n\r\nexport class Category {\r\n id: string;\r\n keyId: string;\r\n code?: string;\r\n name: string;\r\n isHidden: boolean;\r\n isCustom: boolean;\r\n isEmpty: boolean;\r\n isArchived: boolean;\r\n allRecordsCount: number;\r\n allowRecords: boolean;\r\n allowCustomCategories: boolean;\r\n myAccessLevel: AccessLevel;\r\n sharedAccess: SharedAccess[];\r\n}\r\n\r\nexport class CurrentCategory extends Category {\r\n parents: Category[];\r\n}\r\n\r\nexport class VaultCategory {\r\n category?: CurrentCategory;\r\n subCategories?: Category[];\r\n records?: VaultRecord[];\r\n}\r\n\r\nexport class NewCategory {\r\n name: string;\r\n code?: string;\r\n isCustom: boolean;\r\n allowRecords: boolean;\r\n allowCustomCategories: boolean;\r\n categoryIds?: string[];\r\n}\r\n\r\nexport class UpdatedCategory {\r\n name: string;\r\n code?: string;\r\n isCustom: boolean;\r\n allowRecords: boolean;\r\n allowCustomCategories: boolean;\r\n}\r\n\r\nexport class Vault {\r\n id: string;\r\n keyId: string;\r\n name?: string;\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport { LrApolloService } from '../api/lr-apollo.service';\r\nimport { KeyMetaService } from '../cryptography/key-meta.service';\r\nimport { RecordContentFilter } from '../record/record.gql';\r\nimport { HasEdges, HasKeyGraphEdges } from '../_common/types';\r\nimport {\r\n GetRootDirectoryIdsQuery,\r\n DefaultVaultFilter,\r\n CategoryFilter,\r\n CreateVaultMutation,\r\n CreateCategoryMutation,\r\n DeleteCategoryMutation,\r\n DirectoryType,\r\n GetCategoriesQuery,\r\n GetCategoryQuery,\r\n GetMySharedCategoriesQuery,\r\n GetMySharedCategoriesQueryType,\r\n GetTrustedPartyCategoriesQuery,\r\n GetTrustedPartyCategoriesQueryType,\r\n RecordFilter,\r\n UpdateCategoryMutation,\r\n UnarchiveDirectoryMutation,\r\n ArchiveDirectoryMutation,\r\n GetVaultsQuery,\r\n} from './category.gql';\r\nimport {\r\n AccessLevel,\r\n Category,\r\n NewCategory,\r\n UpdatedCategory,\r\n VaultCategory,\r\n VaultRecord,\r\n Vault,\r\n} from './category.types';\r\nimport { LrBadStateException } from '../_common/exceptions';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class CategoryService {\r\n constructor(\r\n private lrApollo: LrApolloService,\r\n private keyMetaService: KeyMetaService,\r\n private keyGraph: KeyGraphService\r\n ) {}\r\n\r\n public async getRootDirectoryIds(\r\n input: { archived: boolean } = null\r\n ): Promise<string[]> {\r\n const { rootDirectories } = await this.lrApollo.query<any>({\r\n query: GetRootDirectoryIdsQuery,\r\n variables: {\r\n archived: input && input.archived,\r\n },\r\n });\r\n return rootDirectories.edges.map((edge) => edge.node.id);\r\n }\r\n\r\n public async getDefaultVault(): Promise<Vault> {\r\n const { list } = await this.lrApollo.query<HasKeyGraphEdges<any>>({\r\n query: GetVaultsQuery,\r\n variables: {\r\n plainMetaFilter: DefaultVaultFilter,\r\n },\r\n });\r\n\r\n const defaultVaults = await this.mapVaults(list);\r\n if (defaultVaults.length > 1) {\r\n throw new LrBadStateException('There are more than one default vaults');\r\n }\r\n\r\n return defaultVaults[0] || null;\r\n }\r\n\r\n public async getCategories(\r\n input: { archived: boolean } = null\r\n ): Promise<Category[]> {\r\n const res: any = await this.lrApollo.query<HasKeyGraphEdges<any>>({\r\n query: GetCategoriesQuery,\r\n variables: {\r\n vaultFilter: DefaultVaultFilter,\r\n categoryFilter: CategoryFilter,\r\n recordFilter: RecordFilter,\r\n archived: input && input.archived,\r\n },\r\n });\r\n\r\n if (res.vaults.edges.length > 1) {\r\n throw new LrBadStateException('There is more than one default vault');\r\n } else if (res.vaults.edges.length < 1) {\r\n console.error('There is no default vault.');\r\n return [];\r\n } else {\r\n return await this.mapCategories(\r\n res.vaults.edges[0].node.childDirectoryLinks\r\n );\r\n }\r\n }\r\n\r\n public async getTrustedPartyCategories(\r\n trustedPartyId: string\r\n ): Promise<{ categories: Category[]; records?: VaultRecord[] }> {\r\n const {\r\n tp,\r\n } = await this.lrApollo.query<GetTrustedPartyCategoriesQueryType>({\r\n query: GetTrustedPartyCategoriesQuery,\r\n variables: {\r\n trustedPartyId,\r\n categoryFilter: CategoryFilter,\r\n recordFilter: RecordFilter,\r\n contentFilter: RecordContentFilter,\r\n },\r\n });\r\n return {\r\n categories: await this.mapCategories(tp.sharedItems.list),\r\n records: await this.mapRecords(tp.sharedItems.records),\r\n };\r\n }\r\n\r\n public async getMySharedCategories(\r\n trustedPartyId: string\r\n ): Promise<{ categories: Category[]; records?: VaultRecord[] }> {\r\n const { tp } = await this.lrApollo.query<GetMySharedCategoriesQueryType>({\r\n query: GetMySharedCategoriesQuery,\r\n variables: {\r\n trustedPartyId,\r\n categoryFilter: CategoryFilter,\r\n recordFilter: RecordFilter,\r\n contentFilter: RecordContentFilter,\r\n },\r\n });\r\n return {\r\n categories: await this.mapCategories(tp.myItems.list),\r\n records: await this.mapRecords(tp.myItems.records),\r\n };\r\n }\r\n\r\n public async getCategory(categoryId: string): Promise<VaultCategory> {\r\n const { category } = await this.lrApollo.query<any>({\r\n query: GetCategoryQuery(),\r\n variables: {\r\n id: categoryId,\r\n categoryFilter: CategoryFilter,\r\n recordFilter: RecordFilter,\r\n contentFilter: RecordContentFilter,\r\n },\r\n });\r\n\r\n return {\r\n category: {\r\n ...(await this.mapCategory(category)),\r\n parents: await this.mapParentCategories(category),\r\n },\r\n subCategories: await this.mapCategories(category.subCategories),\r\n records: await this.mapRecords(category.records),\r\n };\r\n }\r\n\r\n private async mapVaults(list: HasEdges<any>): Promise<Vault[]> {\r\n return Promise.all<Vault>(\r\n list.edges.map((edge) => this.mapVault(edge.node))\r\n );\r\n }\r\n\r\n private async mapCategories(list: HasEdges<any>) {\r\n return (\r\n await Promise.all<Category>(\r\n list.edges\r\n .map((x) => x.node)\r\n .map((x) => x.childDirectory || x)\r\n .map(\r\n (node: {\r\n id;\r\n keyId;\r\n plainMeta;\r\n cipherMeta;\r\n descendantDirectories;\r\n accessRoles;\r\n archived;\r\n }) => this.mapCategory(node)\r\n )\r\n )\r\n )\r\n .filter((x) => x)\r\n .sort((x, y) => (x.name === y.name ? 0 : x.name > y.name ? 1 : -1));\r\n }\r\n\r\n private async mapRecords(list: HasEdges<any>) {\r\n return (\r\n await Promise.all<VaultRecord>(\r\n list.edges\r\n .map((x) => x.node)\r\n .map((x) => x.childDirectory || x)\r\n .map(\r\n (node: {\r\n id;\r\n keyId;\r\n plainMeta;\r\n cipherMeta;\r\n created;\r\n modified;\r\n content;\r\n accessRoles;\r\n archived;\r\n }) => this.mapRecord(node)\r\n )\r\n )\r\n )\r\n .filter((x) => x)\r\n .sort((x, y) => (x.name === y.name ? 0 : x.name > y.name ? 1 : -1));\r\n }\r\n\r\n public async createDefaultVault(): Promise<string> {\r\n const secureContent = '';\r\n const wrappedContent = await this.keyMetaService.wrapContent(secureContent);\r\n\r\n const response = await this.lrApollo.mutate<any>({\r\n mutation: CreateVaultMutation,\r\n variables: {\r\n plainMeta: JSON.stringify({\r\n directoryType: DirectoryType.Vault,\r\n default: true,\r\n }),\r\n cipherMeta: wrappedContent.cipherMeta,\r\n parentRootDirectory: wrappedContent.rootKey,\r\n },\r\n });\r\n\r\n return response.new.vault.id;\r\n }\r\n\r\n public async createCategory(newCategory: NewCategory): Promise<string> {\r\n const secureContent = {\r\n name: newCategory.name,\r\n code: newCategory.code,\r\n isCustom: newCategory.isCustom,\r\n allowRecords: newCategory.allowRecords,\r\n allowCustomCategories: newCategory.allowCustomCategories,\r\n };\r\n const wrappedContent = await this.keyMetaService.wrapContent(\r\n secureContent,\r\n newCategory.categoryIds\r\n );\r\n\r\n const response = await this.lrApollo.mutate<any>({\r\n mutation: CreateCategoryMutation,\r\n variables: {\r\n plainMeta: JSON.stringify({\r\n directoryType: DirectoryType.Category,\r\n isHidden: false,\r\n }),\r\n cipherMeta: wrappedContent.cipherMeta,\r\n parentDirectories: wrappedContent.wrappedKeys,\r\n parentRootDirectory: wrappedContent.rootKey,\r\n },\r\n });\r\n\r\n return response.new.category.id;\r\n }\r\n\r\n public async updateCategory(\r\n categoryId: string,\r\n keyId: string,\r\n updatedCategory: UpdatedCategory\r\n ): Promise<void> {\r\n const secureContent = {\r\n name: updatedCategory.name,\r\n code: updatedCategory.code,\r\n isCustom: updatedCategory.isCustom,\r\n allowRecords: updatedCategory.allowRecords,\r\n allowCustomCategories: updatedCategory.allowCustomCategories,\r\n };\r\n\r\n const cipherMeta = await this.keyGraph.encryptToString(\r\n keyId,\r\n secureContent\r\n );\r\n\r\n await this.lrApollo.mutate({\r\n mutation: UpdateCategoryMutation,\r\n variables: {\r\n input: {\r\n directoryId: categoryId,\r\n cipherMeta,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async setCategoryVisibility(\r\n categoryId: string,\r\n hide: boolean\r\n ): Promise<void> {\r\n await this.lrApollo.mutate({\r\n mutation: UpdateCategoryMutation,\r\n variables: {\r\n input: {\r\n directoryId: categoryId,\r\n plainMeta: JSON.stringify({\r\n directoryType: DirectoryType.Category,\r\n isHidden: hide,\r\n }),\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async deleteCategory(categoryId: string): Promise<void> {\r\n await this.lrApollo.mutate({\r\n mutation: DeleteCategoryMutation,\r\n variables: { categoryId },\r\n });\r\n }\r\n\r\n public async archiveCategory(\r\n categoryId: string,\r\n recursive: boolean\r\n ): Promise<void> {\r\n return this.archiveDirectory(categoryId, recursive);\r\n }\r\n\r\n public async unarchiveCategory(\r\n categoryId: string,\r\n recursive: boolean\r\n ): Promise<void> {\r\n return this.unarchiveDirectory(categoryId, recursive);\r\n }\r\n\r\n public async archiveDirectory(\r\n directoryId: string,\r\n recursive: boolean\r\n ): Promise<void> {\r\n await this.lrApollo.mutate({\r\n mutation: ArchiveDirectoryMutation,\r\n variables: {\r\n input: {\r\n directoryId,\r\n recursive,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async unarchiveDirectory(\r\n directoryId: string,\r\n recursive: boolean\r\n ): Promise<void> {\r\n await this.lrApollo.mutate({\r\n mutation: UnarchiveDirectoryMutation,\r\n variables: {\r\n input: {\r\n directoryId,\r\n recursive,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async mapVault(node: {\r\n id;\r\n keyId;\r\n plainMeta;\r\n cipherMeta;\r\n }): Promise<Vault> {\r\n try {\r\n const { name } = (await this.keyMetaService.decryptMeta(node)) || {};\r\n return {\r\n id: node.id,\r\n keyId: node.keyId,\r\n name,\r\n };\r\n } catch (e) {\r\n console.error('Failed to decrypt Vault.', e, node);\r\n return null;\r\n }\r\n }\r\n\r\n public async mapParentCategories(category: {\r\n parentCategories: any;\r\n }): Promise<Category[]> {\r\n if (\r\n !category.parentCategories ||\r\n !category.parentCategories.edges ||\r\n !category.parentCategories.edges.length\r\n ) {\r\n return [];\r\n }\r\n const node = category.parentCategories.edges[0].node.parentDirectory;\r\n\r\n return [\r\n ...(await this.mapParentCategories(node)),\r\n await this.mapCategory(node),\r\n ];\r\n }\r\n\r\n public async mapCategory(node: {\r\n id;\r\n keyId;\r\n plainMeta;\r\n cipherMeta;\r\n descendantDirectories;\r\n accessRoles: any[];\r\n archived;\r\n }): Promise<Category> {\r\n try {\r\n const { name, isCustom, allowRecords, allowCustomCategories, code } =\r\n (await this.keyMetaService.decryptMeta(node)) || {};\r\n const { isHidden } = (node.plainMeta && JSON.parse(node.plainMeta)) || {};\r\n\r\n const isOwner =\r\n node.accessRoles &&\r\n node.accessRoles.some((x) => x.role === AccessLevel.Owner);\r\n\r\n return {\r\n id: node.id,\r\n keyId: node.keyId,\r\n code,\r\n name,\r\n isHidden: !!isHidden,\r\n isCustom: !!isCustom,\r\n isArchived: !!node.archived,\r\n allowRecords: !!allowRecords,\r\n allowCustomCategories: !!allowCustomCategories,\r\n isEmpty: node.descendantDirectories\r\n ? node.descendantDirectories.recordsCount === 0\r\n : null,\r\n allRecordsCount: node.descendantDirectories?.recordsCount, // Need this for testing.\r\n myAccessLevel: isOwner ? AccessLevel.Owner : node.accessRoles[0].role,\r\n sharedAccess: isOwner\r\n ? node.accessRoles\r\n .filter((x) => x.role !== AccessLevel.Owner)\r\n .map((x) => ({\r\n trustedPartyId: x.trustedParty && x.trustedParty.id,\r\n accessLevel: x.role,\r\n isInherited: x.method === 'inherited',\r\n inheritedFrom: x.inheritedFrom && x.inheritedFrom.id,\r\n }))\r\n : [],\r\n };\r\n } catch (e) {\r\n console.error('Failed to decrypt Category.', e, node);\r\n return null;\r\n }\r\n }\r\n\r\n public async mapRecord(node: {\r\n id;\r\n keyId;\r\n plainMeta;\r\n cipherMeta;\r\n created;\r\n modified;\r\n content;\r\n accessRoles: any[];\r\n archived;\r\n }): Promise<VaultRecord> {\r\n try {\r\n const contents = node.content.edges[0].node.childFile;\r\n const { name, recordType } =\r\n (await this.keyMetaService.decryptMeta(\r\n contents.currentVersion.state\r\n )) || {};\r\n\r\n const isOwner =\r\n node.accessRoles &&\r\n node.accessRoles.some((x) => x.role === AccessLevel.Owner);\r\n\r\n return {\r\n id: node.id,\r\n keyId: node.keyId,\r\n name,\r\n recordType,\r\n isArchived: !!node.archived,\r\n createdOn: node.created,\r\n lastModified:\r\n new Date(node.modified) >\r\n new Date(contents.currentVersion.state.modified)\r\n ? node.modified\r\n : contents.currentVersion.state.modified,\r\n myAccessLevel: isOwner ? AccessLevel.Owner : node.accessRoles[0].role,\r\n sharedAccess: isOwner\r\n ? node.accessRoles\r\n .filter((x) => x.role !== AccessLevel.Owner)\r\n .map((x) => ({\r\n trustedPartyId: x.trustedParty && x.trustedParty.id,\r\n accessLevel: x.role,\r\n isInherited: x.method === 'inherited',\r\n inheritedFrom: x.inheritedFrom && x.inheritedFrom.id,\r\n }))\r\n : [],\r\n };\r\n } catch (e) {\r\n console.error('Failed to decrypt Record.', e);\r\n return null as VaultRecord;\r\n }\r\n }\r\n}\r\n","import { HttpClient } from '@angular/common/http';\r\nimport { Injectable } from '@angular/core';\r\nimport { CategoryService } from './category.service';\r\nimport {\r\n AccessLevel,\r\n Category,\r\n CurrentCategory,\r\n DefaultCategory,\r\n VaultCategory,\r\n} from './category.types';\r\n\r\nexport class LoadedCategoryTree {\r\n categories: CurrentCategory[];\r\n missingCategories: string[][];\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class CategoryMetaService {\r\n private categories: DefaultCategory[];\r\n\r\n constructor(\r\n private http: HttpClient,\r\n private categoryService: CategoryService\r\n ) {}\r\n\r\n public async getCoreCategories(): Promise<DefaultCategory[]> {\r\n if (!this.categories) {\r\n this.categories = await this.http\r\n .get<DefaultCategory[]>('/assets/meta/categories.json')\r\n .toPromise();\r\n }\r\n return Promise.resolve(this.categories);\r\n }\r\n\r\n async loadCategories(\r\n categoryTrees: string[][],\r\n selectedCategoryId?: string,\r\n trustedPartyId?: string\r\n ): Promise<LoadedCategoryTree> {\r\n const rootCategories = trustedPartyId\r\n ? (await this.categoryService.getTrustedPartyCategories(trustedPartyId))\r\n .categories\r\n : await this.categoryService.getCategories();\r\n\r\n const selectedCategory = selectedCategoryId\r\n ? await this.categoryService.getCategory(selectedCategoryId)\r\n : null;\r\n\r\n const categoryPromises = categoryTrees.map(async (x) => ({\r\n categoryTree: x,\r\n category: await this.loadCategory(\r\n [...x],\r\n rootCategories,\r\n selectedCategory\r\n ),\r\n }));\r\n\r\n const loadedCategories = await Promise.all(categoryPromises);\r\n\r\n const loadedCategoryTree: LoadedCategoryTree = {\r\n categories: [],\r\n missingCategories: [],\r\n };\r\n\r\n loadedCategories.forEach((x) =>\r\n x.category\r\n ? loadedCategoryTree.categories.push(x.category)\r\n : loadedCategoryTree.missingCategories.push(x.categoryTree)\r\n );\r\n\r\n return loadedCategoryTree;\r\n }\r\n\r\n async loadCategoriesForRole(\r\n categories: { category: string[]; accessLevel: AccessLevel }[]\r\n ): Promise<{ category: CurrentCategory; accessLevel: AccessLevel }[]> {\r\n const rootCategories = await this.categoryService.getCategories();\r\n\r\n return await Promise.all(\r\n categories.map(async (x) => ({\r\n category: await this.loadCategory([...x.category], rootCategories),\r\n accessLevel: x.accessLevel,\r\n }))\r\n );\r\n }\r\n\r\n private async loadCategory(\r\n categoryTree: string[],\r\n categories: Category[],\r\n selectedCategory?: VaultCategory\r\n ): Promise<CurrentCategory> {\r\n const name = categoryTree.shift();\r\n\r\n const currentCategory = categories.find(\r\n (x) => x.code === name && !x.isCustom\r\n );\r\n\r\n if (currentCategory) {\r\n if (categoryTree.length) {\r\n const { subCategories } = await this.categoryService.getCategory(\r\n currentCategory.id\r\n );\r\n return this.loadCategory(categoryTree, subCategories, selectedCategory);\r\n } else {\r\n const { category } = await this.categoryService.getCategory(\r\n currentCategory.id\r\n );\r\n\r\n if (\r\n selectedCategory &&\r\n selectedCategory.category.parents.some((x) => x.id === category.id)\r\n ) {\r\n return selectedCategory.category;\r\n }\r\n return category;\r\n }\r\n } else if (categoryTree.length) {\r\n return this.loadCategory(categoryTree, categories, selectedCategory);\r\n } else {\r\n return null;\r\n }\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport { FileType, DeleteFileMutation, CreateFileMutation } from './record.gql';\r\nimport { NewAttachment, NewOrUpdatedAttachment } from './record.types';\r\nimport { LrApolloService } from '../api/lr-apollo.service';\r\nimport { KeyMetaService } from '../cryptography/key-meta.service';\r\nimport { FileService } from '../api/file.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class RecordAttachmentService {\r\n constructor(\r\n private fileService: FileService,\r\n private lrApollo: LrApolloService,\r\n private keyMetaService: KeyMetaService,\r\n private keyGraph: KeyGraphService\r\n ) {}\r\n\r\n async downloadAttachment(\r\n fileStateNodeId: string,\r\n keyId: string\r\n ): Promise<any> {\r\n const encryptedFile = await this.fileService.downloadEncryptedFile(\r\n fileStateNodeId\r\n );\r\n\r\n return await this.keyGraph.decryptFile(keyId, encryptedFile);\r\n }\r\n\r\n async uploadAttachments(\r\n recordId: string,\r\n attachments: NewOrUpdatedAttachment[]\r\n ): Promise<string[]> {\r\n const fileIds = await Promise.all(\r\n (attachments || []).map(async (x) => {\r\n if (x.fileId) {\r\n if (x.isDeleted) {\r\n await this.deleteAttachment(x.fileId);\r\n return null;\r\n } else {\r\n return x.fileId;\r\n }\r\n } else {\r\n return await this.addAttachment(recordId, x);\r\n }\r\n })\r\n );\r\n return fileIds.filter((x) => x);\r\n }\r\n\r\n private async addAttachment(\r\n recordId: string,\r\n attachment: NewAttachment\r\n ): Promise<string> {\r\n const secureContent = {\r\n name: attachment.name,\r\n fieldId: attachment.fieldId,\r\n fileType: attachment.file.type,\r\n fileSize: attachment.file.size,\r\n lastModified: attachment.file.lastModified,\r\n };\r\n const fileContent = await this.fileService.loadFile(attachment.file);\r\n const doubleWrappedContent = await this.keyMetaService.doubleWrapContent(\r\n secureContent,\r\n [recordId],\r\n fileContent\r\n );\r\n\r\n const contentId = await this.fileService.uploadEncryptedFile({\r\n encryptedContent: doubleWrappedContent.cipherFileContent,\r\n fileName: attachment.name,\r\n });\r\n\r\n // Save file\r\n const response = await this.lrApollo.mutate<any>({\r\n mutation: CreateFileMutation,\r\n variables: {\r\n input: {\r\n plainMeta: JSON.stringify({ fileType: FileType.RecordAttachment }),\r\n wrappedStateKey: doubleWrappedContent.doubleWrappedKey,\r\n cipherMeta: doubleWrappedContent.cipherMeta,\r\n parentDirectories: doubleWrappedContent.wrappedKeys.map((x) => ({\r\n directoryId: x.directoryId,\r\n wrappingKeyId: x.wrappingKeyId,\r\n wrappedFileKey: x.wrappedKey,\r\n })),\r\n contentResource: contentId,\r\n },\r\n },\r\n });\r\n return response.createFile.file.id;\r\n }\r\n\r\n async deleteAttachment(fileId: string): Promise<void> {\r\n await this.lrApollo.mutate({\r\n mutation: DeleteFileMutation,\r\n variables: { fileId },\r\n });\r\n }\r\n}\r\n","import {\r\n AccessLevel,\r\n Category,\r\n SharedAccess,\r\n} from '../category/category.types';\r\nimport {\r\n RecordFieldType,\r\n RecordTypeFieldOption,\r\n RecordTypeSummary,\r\n} from '../record-type/record-type.types';\r\n\r\nexport type RecordFieldValue =\r\n | string\r\n | string[]\r\n | RecordTypeFieldOption\r\n | RecordTypeFieldOption[]\r\n | RecordField[];\r\n\r\nexport class RecordField {\r\n id?: string;\r\n label: string;\r\n type: RecordFieldType;\r\n\r\n value?: RecordFieldValue;\r\n}\r\n\r\nexport class RecordAttachment {\r\n fileId: string;\r\n keyId: string;\r\n fieldId?: string;\r\n contentId: string;\r\n\r\n name: string;\r\n fileType: string;\r\n fileSize: number;\r\n lastModified: number | Date;\r\n}\r\n\r\nexport class LrRecord {\r\n id: string;\r\n // This is the key of the directory that represents the record\r\n keyId: string;\r\n // This is the key of the file contained in side the record that holds the record's fields.\r\n updateKeyId: string;\r\n updateId: string;\r\n\r\n name: string;\r\n categories?: Category[][];\r\n fields?: RecordField[];\r\n attachments?: RecordAttachment[];\r\n\r\n recordType: RecordTypeSummary;\r\n createdOn: string | Date;\r\n lastModified: string | Date;\r\n isArchived: boolean;\r\n myAccessLevel: AccessLevel;\r\n sharedAccess: SharedAccess[];\r\n}\r\n\r\nexport class NewAttachment {\r\n fieldId?: string;\r\n name: string;\r\n file?: File;\r\n}\r\n\r\nexport class NewRecord {\r\n name: string;\r\n recordType: RecordTypeSummary;\r\n categoryIds: string[];\r\n\r\n fields?: RecordField[];\r\n attachments?: NewAttachment[];\r\n}\r\n\r\nexport class NewOrUpdatedAttachment extends NewAttachment {\r\n fileId?: string;\r\n isDeleted?: boolean;\r\n}\r\n\r\nexport class UpdatedRecord {\r\n name: string;\r\n recordType: RecordTypeSummary;\r\n\r\n fields?: RecordField[];\r\n attachments?: NewOrUpdatedAttachment[];\r\n}\r\n","import { RecordAttachmentService } from './record-attachment.service';\r\nimport { Injectable } from '@angular/core';\r\nimport { LrApolloService } from '../api/lr-apollo.service';\r\nimport { CategoryFilter } from '../category/category.gql';\r\nimport { KeyMetaService } from '../cryptography/key-meta.service';\r\nimport { DirectoryType } from './../category/category.gql';\r\nimport {\r\n LrRecord,\r\n NewRecord,\r\n UpdatedRecord,\r\n RecordAttachment,\r\n} from './record.types';\r\nimport {\r\n CreateRecordContainerMutation,\r\n CreateRecordMutation,\r\n DeleteRecordMutation,\r\n FileType,\r\n GetRecordQuery,\r\n RecordAttachmentFilter,\r\n RecordContentFilter,\r\n UpdateRecordContainerMutation,\r\n UpdateRecordMutation,\r\n} from './record.gql';\r\nimport { Category, AccessLevel } from '../category/category.types';\r\nimport { CategoryService } from '../category/category.service';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class RecordService {\r\n constructor(\r\n private lrApollo: LrApolloService,\r\n private keyMetaService: KeyMetaService,\r\n private categoryService: CategoryService,\r\n private recordAttachmentService: RecordAttachmentService\r\n ) {}\r\n\r\n public async getRecord(recordId: string): Promise<LrRecord> {\r\n const { record } = await this.lrApollo.query<any>({\r\n query: GetRecordQuery(),\r\n variables: {\r\n id: recordId,\r\n categoryFilter: CategoryFilter,\r\n contentFilter: RecordContentFilter,\r\n attachmentsFilter: RecordAttachmentFilter,\r\n },\r\n });\r\n const contents = record.content.edges[0].node.childFile;\r\n const { name, recordType, fields } =\r\n (await this.keyMetaService.decryptMeta(contents.currentVersion.state)) ||\r\n {};\r\n const categories = await Promise.all<Category[]>(\r\n record.parentCategories.edges.map(async (x: any) => [\r\n ...(await this.categoryService.mapParentCategories(\r\n x.node.parentDirectory\r\n )),\r\n await this.categoryService.mapCategory(x.node.parentDirectory),\r\n ])\r\n );\r\n const attachments = await this.mapAttachments(record.attachments.edges);\r\n const isOwner =\r\n record.accessRoles &&\r\n record.accessRoles.some((x) => x.role === AccessLevel.Owner);\r\n\r\n return {\r\n id: record.id,\r\n keyId: record.keyId,\r\n updateKeyId: contents.keyId,\r\n updateId: contents.id,\r\n name,\r\n recordType,\r\n fields,\r\n categories,\r\n attachments,\r\n myAccessLevel: isOwner ? AccessLevel.Owner : record.accessRoles[0].role,\r\n sharedAccess: isOwner\r\n ? record.accessRoles\r\n .filter((x) => x.role !== AccessLevel.Owner)\r\n .map((x) => ({\r\n trustedPartyId: x.trustedParty && x.trustedParty.id,\r\n accessLevel: x.role,\r\n isInherited: x.method === 'inherited',\r\n inheritedFrom: x.inheritedFrom && x.inheritedFrom.id,\r\n }))\r\n : [],\r\n isArchived: !!record.archived,\r\n createdOn: record.created,\r\n lastModified:\r\n new Date(record.modified) >\r\n new Date(contents.currentVersion.state.modified)\r\n ? record.modified\r\n : contents.currentVersion.state.modified,\r\n };\r\n }\r\n\r\n private async mapAttachments(\r\n attachments: any[]\r\n ): Promise<RecordAttachment[]> {\r\n return await Promise.all<RecordAttachment>(\r\n attachments\r\n .map((x) => x.node.childFile)\r\n .map(async (x: any) => {\r\n const { name, fieldId, fileType, fileSize, lastModified } =\r\n (await this.keyMetaService.decryptMeta(x.currentVersion.state)) ||\r\n {};\r\n\r\n return {\r\n fileId: x.id,\r\n keyId: x.currentVersion.state.keyId,\r\n contentId: x.currentVersion.state.id,\r\n fieldId,\r\n name,\r\n fileType,\r\n fileSize,\r\n lastModified,\r\n };\r\n })\r\n );\r\n }\r\n\r\n public async createRecord(\r\n newRecord: NewRecord\r\n ): Promise<{ recordId: string; attachmentError?: Error }> {\r\n // Create directory that holds the record\r\n const wrappedContent = await this.keyMetaService.wrapContent(\r\n null,\r\n newRecord.categoryIds\r\n );\r\n const response = await this.lrApollo.mutate<any>({\r\n mutation: CreateRecordContainerMutation,\r\n variables: {\r\n plainMeta: JSON.stringify({\r\n directoryType: DirectoryType.Record,\r\n isHidden: false,\r\n }),\r\n parentDirectories: wrappedContent.wrappedKeys,\r\n parentRootDirectory: wrappedContent.rootKey,\r\n },\r\n });\r\n const recordId = response.new.category.id;\r\n const secureContent = {\r\n name: newRecord.name,\r\n recordType: newRecord.recordType,\r\n fields: newRecord.fields,\r\n };\r\n const doubleWrappedContent = await this.keyMetaService.doubleWrapContent(\r\n secureContent,\r\n [recordId]\r\n );\r\n\r\n // Create the file that holds the record contents\r\n await this.lrApollo.mutate({\r\n mutation: CreateRecordMutation,\r\n variables: {\r\n input: {\r\n plainMeta: JSON.stringify({ fileType: FileType.RecordContent }),\r\n wrappedStateKey: doubleWrappedContent.doubleWrappedKey,\r\n cipherMeta: doubleWrappedContent.cipherMeta,\r\n parentDirectories: doubleWrappedContent.wrappedKeys.map((x) => ({\r\n directoryId: x.directoryId,\r\n wrappingKeyId: x.wrappingKeyId,\r\n wrappedFileKey: x.wrappedKey,\r\n })),\r\n },\r\n },\r\n });\r\n\r\n try {\r\n await this.recordAttachmentService.uploadAttachments(\r\n recordId,\r\n newRecord.attachments\r\n );\r\n } catch (e) {\r\n console.error(e);\r\n return { recordId, attachmentError: e };\r\n }\r\n return { recordId };\r\n }\r\n\r\n public async updateRecord(\r\n recordId: string,\r\n updateId: string,\r\n updateKeyId: string,\r\n updatedRecord: UpdatedRecord\r\n ): Promise<{ recordId: string; attachmentError?: Error }> {\r\n const secureContent = {\r\n name: updatedRecord.name,\r\n recordType: updatedRecord.recordType,\r\n fields: updatedRecord.fields,\r\n };\r\n const reWrappedContent = await this.keyMetaService.reWrapContent(\r\n updateKeyId,\r\n secureContent\r\n );\r\n\r\n await this.lrApollo.mutate({\r\n mutation: UpdateRecordMutation,\r\n variables: {\r\n input: {\r\n fileId: updateId,\r\n plainMeta: JSON.stringify({ fileType: FileType.RecordContent }),\r\n wrappedStateKey: reWrappedContent.doubleWrappedKey,\r\n cipherMeta: reWrappedContent.cipherMeta,\r\n },\r\n },\r\n });\r\n\r\n try {\r\n await this.recordAttachmentService.uploadAttachments(\r\n recordId,\r\n updatedRecord.attachments\r\n );\r\n } catch (e) {\r\n console.error(e);\r\n return { recordId, attachmentError: e };\r\n }\r\n return { recordId };\r\n }\r\n\r\n public async archiveRecord(recordId: string): Promise<void> {\r\n // All content of the record should also be archived, hence, recursive=true\r\n return this.categoryService.archiveDirectory(recordId, true);\r\n }\r\n\r\n public async unarchiveRecord(recordId: string): Promise<void> {\r\n // All content of the record should also be unarchived, hence, recursive=true\r\n return this.categoryService.unarchiveDirectory(recordId, true);\r\n }\r\n\r\n public async deleteRecord(recordId: string): Promise<void> {\r\n await this.lrApollo.mutate({\r\n mutation: DeleteRecordMutation,\r\n variables: { recordId },\r\n });\r\n }\r\n}\r\n","export enum RecordFieldType {\r\n Text = 'text',\r\n Email = 'email',\r\n Url = 'url',\r\n Phone = 'phone',\r\n Date = 'date',\r\n Password = 'password',\r\n TextArea = 'textArea',\r\n Select = 'select',\r\n SingleChoice = 'singleChoice',\r\n MultiChoice = 'multiChoice',\r\n File = 'file',\r\n MultiFile = 'multiFile',\r\n Record = 'record',\r\n MultiRecord = 'multiRecord',\r\n Group = 'group',\r\n Custom = 'custom',\r\n}\r\n\r\nexport class RecordType {\r\n id: string;\r\n version: number;\r\n name: string;\r\n tags: string[];\r\n\r\n allowAttachments: boolean;\r\n allowCustomFields: boolean;\r\n\r\n fields: RecordTypeField[];\r\n categories: string[][];\r\n categoryNames: string[][];\r\n}\r\n\r\nexport class RecordTypeFieldOption {\r\n name: string;\r\n\r\n categories?: string[][];\r\n}\r\n\r\nexport class RecordTypeField {\r\n id: string;\r\n label: string;\r\n type: RecordFieldType;\r\n placeholder?: string;\r\n hint?: string;\r\n isMandatory?: boolean;\r\n\r\n options?: RecordTypeFieldOption[];\r\n extensions?: string;\r\n recordTypeIds?: string[];\r\n fields?: RecordTypeField[];\r\n}\r\n\r\nexport class RecordTypeSummary {\r\n id: string;\r\n version: number;\r\n name: string;\r\n}\r\n","import { HttpClient } from '@angular/common/http';\r\nimport { Injectable } from '@angular/core';\r\nimport { Category, DefaultCategory } from '../category/category.types';\r\nimport { RecordType } from './record-type.types';\r\n\r\nconst arraysEqual = (a: string[], b: string[]) => {\r\n if (a === b) return true;\r\n if (a == null || b == null) return false;\r\n if (a.length !== b.length) return false;\r\n\r\n for (let i = 0; i < a.length; ++i) {\r\n if (a[i] !== b[i]) return false;\r\n }\r\n return true;\r\n};\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class RecordTypeService {\r\n private recordTypes: RecordType[];\r\n private categories: DefaultCategory[];\r\n\r\n constructor(private http: HttpClient) {}\r\n\r\n public async getRecordTypes(): Promise<RecordType[]> {\r\n if (!this.recordTypes) {\r\n this.recordTypes = await this.http\r\n .get<RecordType[]>('/assets/meta/record-types.json')\r\n .toPromise();\r\n }\r\n if (!this.categories) {\r\n this.categories = await this.http\r\n .get<DefaultCategory[]>('/assets/meta/categories.json')\r\n .toPromise();\r\n }\r\n\r\n const subCategories = this.categories\r\n .map((cat) => cat.subCategories)\r\n .reduce((acc, next) => [...acc, ...next], []);\r\n\r\n const recordTypesWithCategories = this.recordTypes.map((recordType) => ({\r\n ...recordType,\r\n categoryNames: recordType.categories.map((cat) => {\r\n return cat.map((categoryCode) => {\r\n const subCat = subCategories.find((c) => c.code === categoryCode);\r\n if (subCat) {\r\n return subCat.name;\r\n } else {\r\n return this.categories.find((c) => c.code === categoryCode).name;\r\n }\r\n });\r\n }),\r\n }));\r\n return Promise.resolve(recordTypesWithCategories);\r\n }\r\n\r\n public async getRecordType(recordTypeId: string): Promise<RecordType> {\r\n return (await this.getRecordTypes()).find((x) => x.id === recordTypeId);\r\n }\r\n\r\n public async getRecordTypesForCategory(\r\n categoryTree: string[]\r\n ): Promise<RecordType[]> {\r\n const recordTypes = await this.getRecordTypes();\r\n\r\n return recordTypes.filter((x) =>\r\n x.categories.some((y) => arraysEqual(y, categoryTree))\r\n );\r\n }\r\n}\r\n","import {\r\n DecryptedOtk,\r\n PreparedPermissions,\r\n UserSharedKey,\r\n} from '../api/key-exchange.types';\r\nimport { KeyExchangeMessage } from './../api/key-exchange.types';\r\nimport { AccessLevel } from './../category/category.types';\r\nimport { TrustedPartyDetails } from './../users/profile.types';\r\nimport { FeatureAction } from '../auth/auth.types';\r\n\r\nexport class TrustedPartyRole {\r\n id: string;\r\n name: string;\r\n roleType: TrustedPartyRoleType;\r\n categories: {\r\n category: string[];\r\n accessLevel: AccessLevel;\r\n }[];\r\n}\r\n\r\nexport enum TrustedPartyRoleType {\r\n General = 'general',\r\n Scenario = 'scenario',\r\n}\r\n\r\nexport enum TrustedPartyType {\r\n User = 'user',\r\n Organisation = 'organisation',\r\n}\r\n\r\nexport enum TrustedPartyInviteStatus {\r\n Invited = 'IN_PROGRESS',\r\n Cancelled = 'CANCELLED',\r\n Declined = 'DECLINED',\r\n Completed = 'COMPLETED',\r\n}\r\n\r\nexport class TrustedParties {\r\n parties: TrustedParty[];\r\n invites: TrustedPartyInvite[];\r\n sentInvites: TrustedPartyInvite[];\r\n}\r\n\r\nexport class SharedTrustedPartyDetails extends TrustedPartyDetails {\r\n id: string;\r\n ownedKeyId: string;\r\n sharedKeyId: string;\r\n}\r\n\r\nexport class TrustedPartyInvite {\r\n id: string;\r\n type: TrustedPartyType;\r\n status: TrustedPartyInviteStatus;\r\n token: string;\r\n tokenExpiry: string | Date;\r\n isExpired: boolean;\r\n isSender: boolean;\r\n actionRequired: boolean;\r\n name: string;\r\n email: string;\r\n\r\n details?: TrustedPartyDetails;\r\n message?: KeyExchangeMessage;\r\n mySharedDetails?: TrustedPartyDetails;\r\n mySharedMessage?: KeyExchangeMessage;\r\n\r\n rootKeyCipher: string;\r\n pbkCipher: string;\r\n decryptedOtk: DecryptedOtk;\r\n}\r\n\r\nexport class TPFeatures {\r\n sharedVault: SharedVaultFeature;\r\n}\r\n\r\nexport class SharedVaultFeature {\r\n hasAccess: boolean;\r\n}\r\n\r\nexport class TrustedParty {\r\n id: string;\r\n type: TrustedPartyType;\r\n name: string;\r\n\r\n hasScenarios: boolean;\r\n hasSharedVault: boolean;\r\n details: TrustedPartyDetails;\r\n mySharedDetails: SharedTrustedPartyDetails;\r\n userSharedKey: UserSharedKey;\r\n username: string;\r\n features: TPFeatures;\r\n}\r\n\r\nexport class FoundTrustedParty {\r\n id: string;\r\n email: string;\r\n username: string;\r\n isTrustedParty: boolean;\r\n isMe: boolean;\r\n}\r\n\r\nexport class InviteTrustedParty {\r\n party: { username?: string; email?: string; name?: string; message?: string };\r\n permissions?: PreparedPermissions;\r\n mySharedDetails: TrustedPartyDetails;\r\n}\r\n\r\nexport class AcceptTrustedPartyInvite {\r\n inviteId: string;\r\n inviteToken: string;\r\n decryptedOtk: DecryptedOtk;\r\n mySharedDetails: TrustedPartyDetails;\r\n}\r\n\r\nexport class ConfirmTrustedPartyInvite {\r\n inviteId: string;\r\n initiatorRootKeyCipher: string;\r\n initiatorOneTimePbkCipher: string;\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport gql from 'graphql-tag';\r\nimport { Key } from '../cryptography/cryptography.types';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport { SharedTrustedPartyDetails } from '../trusted-parties/trusted-party.types';\r\nimport { ContactCardName, TrustedPartyDetails } from '../users/profile.types';\r\nimport { User } from '../users/user.types';\r\nimport { KeyGraphField } from '../_common/queries.gql';\r\nimport { LrApolloService } from './lr-apollo.service';\r\n\r\nexport const SharedContactCardFields = `\r\n id\r\n owner {\r\n id\r\n username\r\n }\r\n ownerKey {\r\n id\r\n }\r\n ownerCipherData\r\n receiver {\r\n id\r\n username\r\n }\r\n receiverKey {\r\n id\r\n }\r\n receiverCipherData\r\n sharedKey {\r\n id\r\n }\r\n sharedCipherData\r\n sharedCipherDataSig\r\n sharedCipherDataSigPxk {\r\n id\r\n }\r\n`;\r\n\r\nconst UpdateOwnedContactCard = gql`\r\nmutation UpdateOwnedContactCard(\r\n $input: UpdateOwnedContactCardInput!\r\n) {\r\n updateOwnedContactCard(\r\n input: $input\r\n ) {\r\n ownedContactCard {\r\n ${SharedContactCardFields}\r\n }\r\n }\r\n}`;\r\n\r\ninterface UpdateOwnedContactCard {\r\n updateOwnedContactCard: {\r\n ownedContactCard: SharedContactCard;\r\n };\r\n}\r\n\r\nexport interface SharedContactCard {\r\n id: string;\r\n owner: User;\r\n ownerKey: Key;\r\n ownerCipherData: string;\r\n receiver: User;\r\n receiverKey: Key;\r\n receiverCipherData: string;\r\n sharedKey: Key;\r\n sharedCipherData: string;\r\n // Decrypted\r\n plainOwnerCipherDataJson: any;\r\n plainReceiverCipherDataJson: any;\r\n plainSharedCipherDataJson: any;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class SharedContactCardService {\r\n constructor(\r\n private keyService: KeyService,\r\n private lrApollo: LrApolloService,\r\n private keyGraph: KeyGraphService,\r\n private encryptionService: EncryptionService\r\n ) {}\r\n\r\n async decryptSharedTrustedPartyDetails(\r\n cc: SharedContactCard\r\n ): Promise<SharedTrustedPartyDetails> {\r\n const details = await this.decryptTrustedPartyDetails(cc);\r\n\r\n return {\r\n id: cc.id,\r\n ownedKeyId: cc.ownerKey.id,\r\n sharedKeyId: cc.sharedKey.id,\r\n ...details,\r\n };\r\n }\r\n\r\n async decryptTrustedPartyDetails(\r\n cc: SharedContactCard\r\n ): Promise<TrustedPartyDetails> {\r\n if (cc && cc.sharedKey && cc.sharedCipherData) {\r\n try {\r\n return await this.encryptionService.decrypt(\r\n await this.keyGraph.getJwkKey(cc.sharedKey.id),\r\n cc.sharedCipherData\r\n );\r\n } catch (e) {\r\n console.error('Cannot decrypt trusted party details', e);\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n async updateMySharedContactCard(\r\n id: string,\r\n ownedKeyId: string,\r\n sharedKeyId: string,\r\n contactCard: TrustedPartyDetails\r\n ): Promise<void> {\r\n const ownerKey = await this.keyGraph.getKey(ownedKeyId);\r\n const sharedKey = await this.keyGraph.getKey(sharedKeyId);\r\n const sigPxk = await this.keyService.getCurrentSigPxk();\r\n\r\n const sharedCipherData = await this.encryptionService.encrypt(\r\n sharedKey.jwk,\r\n contactCard\r\n );\r\n const sharedCipherDataSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, sharedCipherData)\r\n );\r\n\r\n const ownerPlainData = {\r\n name: new ContactCardName(contactCard.name),\r\n };\r\n const ownerPlainDataSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, ownerPlainData)\r\n );\r\n\r\n await this.lrApollo.mutate<UpdateOwnedContactCard>({\r\n mutation: UpdateOwnedContactCard,\r\n variables: {\r\n input: {\r\n id,\r\n ownerCipherData: '',\r\n ownerKeyId: ownerKey.id,\r\n sharedCipherDataSig,\r\n sharedKeyId: sharedKey.id,\r\n sigPxkId: sigPxk.id,\r\n ownerPlainDataSig,\r\n },\r\n },\r\n });\r\n }\r\n}\r\n","import gql from 'graphql-tag';\r\nimport { KeyGraphField } from '../_common/queries.gql';\r\nimport {\r\n KeyExchangeFields,\r\n UserSharedKeyFields,\r\n} from '../api/key-exchange.gql';\r\nimport { SharedContactCardFields } from '../api/shared-contact-card.service';\r\n\r\nexport const TrustedPartyProperties = `\r\n id\r\n user {\r\n id\r\n username\r\n }\r\n other{\r\n id\r\n username,\r\n features {\r\n shareVault\r\n }\r\n }\r\n sharedContactCard {\r\n ${SharedContactCardFields}\r\n }\r\n myContactCard {\r\n ${SharedContactCardFields}\r\n }\r\n sharedScenarios {\r\n edges {\r\n node {\r\n id\r\n }\r\n }\r\n }\r\n sharedItems {\r\n directories {\r\n edges {\r\n node {\r\n id\r\n }\r\n }\r\n }\r\n }\r\n currentUserSharedKey {\r\n userSharedKey {\r\n keyExchange {\r\n ${KeyExchangeFields}\r\n }\r\n ${UserSharedKeyFields}\r\n }\r\n }`;\r\n\r\nexport const GetTrustedPartiesQuery = gql`\r\nquery GetTrustedPartiesQuery {\r\n tps {\r\n edges {\r\n node {\r\n ${TrustedPartyProperties}\r\n }\r\n }\r\n }\r\n ${KeyGraphField}\r\n}`;\r\n\r\nexport const GetAllTrustedPartiesQuery = gql`\r\nquery GetAllTrustedPartiesQuery($userId: ID, $isExpired: Boolean, $inviteState: String, $sentInviteState: String) {\r\n tps {\r\n edges {\r\n node {\r\n ${TrustedPartyProperties}\r\n }\r\n }\r\n }\r\n invites: keyExchanges(\r\n responder: $userId\r\n isExpired: $isExpired\r\n state: $inviteState\r\n orderBy: \"state,-created\"\r\n ) {\r\n edges {\r\n node {\r\n ${KeyExchangeFields}\r\n }\r\n }\r\n }\r\n sentInvites: keyExchanges(\r\n initiator: $userId\r\n isExpired: $isExpired\r\n state: $sentInviteState\r\n orderBy: \"state,-created\"\r\n ) {\r\n edges {\r\n node {\r\n ${KeyExchangeFields}\r\n }\r\n }\r\n }\r\n ${KeyGraphField}\r\n}`;\r\n\r\nexport const GetTrustedPartyQuery = gql`\r\nquery GetTrustedPartyQuery($partyId: LrRelayIdInput!) {\r\n tp(id: $partyId) {\r\n ${TrustedPartyProperties}\r\n }\r\n ${KeyGraphField}\r\n}`;\r\n\r\nexport const DeclineTrustedPartyInvitationMutation = gql`\r\n mutation DeclineKeyExchange($input: DeclineKeyExchangeInput!) {\r\n declineKeyExchange(input: $input) {\r\n keyExchange {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const CancelTrustedPartyInvitationMutation = gql`\r\n mutation CancelKeyExchange($input: CancelKeyExchangeInput!) {\r\n cancelKeyExchange(input: $input) {\r\n keyExchange {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const DeleteTrustedPartyMutation = gql`\r\n mutation DeleteTpMutation($input: DeleteTpInput!) {\r\n deleteTp(input: $input) {\r\n id\r\n }\r\n }\r\n`;\r\n\r\nexport const ShareCategoryMutation = gql`\r\n mutation ShareDirectory($input: ShareDirectoryInput!) {\r\n shareDirectory(input: $input) {\r\n tpDirectory {\r\n item {\r\n plainMeta\r\n }\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UnshareCategoryMutation = gql`\r\n mutation UnshareDirectory($input: UnshareDirectoryInput!) {\r\n unshareDirectory(input: $input) {\r\n tpDirectory {\r\n item {\r\n plainMeta\r\n }\r\n }\r\n }\r\n }\r\n`;\r\n","import { HttpClient } from '@angular/common/http';\r\nimport { Injectable } from '@angular/core';\r\nimport { JWK } from 'node-jose';\r\nimport { materialize } from 'rxjs/operators';\r\nimport { KeyExchangeService } from '../api/key-exchange.service';\r\nimport {\r\n DecryptedKeyExchange,\r\n RespondOtkInput,\r\n} from '../api/key-exchange.types';\r\nimport { LrApolloService } from '../api/lr-apollo.service';\r\nimport { SharedContactCardService } from '../api/shared-contact-card.service';\r\nimport { LifeReadyAuthService } from '../auth/life-ready-auth.service';\r\nimport { AccessLevel } from '../category/category.types';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport { UserService } from '../users/user.service';\r\nimport { ContactCardName } from '../users/profile.types';\r\nimport {\r\n CancelTrustedPartyInvitationMutation,\r\n DeclineTrustedPartyInvitationMutation,\r\n DeleteTrustedPartyMutation,\r\n GetAllTrustedPartiesQuery,\r\n GetTrustedPartiesQuery,\r\n GetTrustedPartyQuery,\r\n ShareCategoryMutation,\r\n UnshareCategoryMutation,\r\n} from './trusted-party.gql';\r\nimport {\r\n AcceptTrustedPartyInvite,\r\n ConfirmTrustedPartyInvite,\r\n FoundTrustedParty,\r\n InviteTrustedParty,\r\n TrustedParties,\r\n TrustedParty,\r\n TrustedPartyInvite,\r\n TrustedPartyInviteStatus,\r\n TrustedPartyRole,\r\n TrustedPartyType,\r\n TrustedPartyRoleType,\r\n} from './trusted-party.types';\r\nimport { KeyFactoryService } from '../cryptography/key-factory.service';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class TrustedPartyService {\r\n private trustedPartyRoles: TrustedPartyRole[];\r\n\r\n constructor(\r\n private http: HttpClient,\r\n private lrApollo: LrApolloService,\r\n private sharedContactCardService: SharedContactCardService,\r\n private userService: UserService,\r\n private authService: LifeReadyAuthService,\r\n private keyExchangeService: KeyExchangeService,\r\n private keyGraphService: KeyGraphService,\r\n private keyService: KeyService,\r\n private keyFactory: KeyFactoryService,\r\n private encryptionService: EncryptionService\r\n ) {}\r\n\r\n public async getTrustedParties(): Promise<TrustedParty[]> {\r\n const { tps } = await this.lrApollo.query<any>({\r\n query: GetTrustedPartiesQuery,\r\n });\r\n return await Promise.all(\r\n tps.edges.map((x) => this.mapTrustedParty(x.node))\r\n );\r\n }\r\n\r\n public async getAllTrustedParties(): Promise<TrustedParties> {\r\n const user = await this.authService.getUser();\r\n const { tps, invites, sentInvites } = await this.lrApollo.query<any>({\r\n query: GetAllTrustedPartiesQuery,\r\n variables: {\r\n userId: user.id,\r\n isExpired: false,\r\n },\r\n });\r\n\r\n return {\r\n parties: (\r\n await Promise.all<TrustedParty>(\r\n tps.edges.map((x) => this.mapTrustedParty(x.node))\r\n )\r\n ).filter((x) => x),\r\n invites: (\r\n await Promise.all<TrustedPartyInvite>(\r\n invites.edges.map(async (x) =>\r\n this.mapInvite(\r\n await this.keyExchangeService.decryptKeyExchange(x.node)\r\n )\r\n )\r\n )\r\n )\r\n .filter((x) => x.status !== TrustedPartyInviteStatus.Completed)\r\n .filter(\r\n (x) =>\r\n x.status !== TrustedPartyInviteStatus.Invited || x.actionRequired\r\n ),\r\n sentInvites: (\r\n await Promise.all<TrustedPartyInvite>(\r\n sentInvites.edges.map(async (x) =>\r\n this.mapInvite(\r\n await this.keyExchangeService.decryptKeyExchange(x.node)\r\n )\r\n )\r\n )\r\n ).filter((x) => x.status !== TrustedPartyInviteStatus.Completed),\r\n };\r\n }\r\n\r\n public async getTrustedParty(partyId: string): Promise<TrustedParty> {\r\n const { tp } = await this.lrApollo.query<any>({\r\n query: GetTrustedPartyQuery,\r\n variables: { partyId },\r\n });\r\n return await this.mapTrustedParty(tp);\r\n }\r\n\r\n public async getTrustedPartyRoles(\r\n roleType: TrustedPartyRoleType = TrustedPartyRoleType.General\r\n ): Promise<TrustedPartyRole[]> {\r\n if (!this.trustedPartyRoles) {\r\n this.trustedPartyRoles = await this.http\r\n .get<TrustedPartyRole[]>('/assets/meta/trusted-party-roles.json')\r\n .toPromise();\r\n }\r\n return Promise.resolve(\r\n this.trustedPartyRoles.filter((x) => x.roleType === roleType)\r\n );\r\n }\r\n\r\n public async findByEmail(email: string): Promise<FoundTrustedParty> {\r\n try {\r\n const user = await this.userService.getUserByEmail(email);\r\n\r\n return user\r\n ? {\r\n id: user.id,\r\n email,\r\n username: user.username,\r\n isTrustedParty: user.haveTp,\r\n isMe: user.isCurrentUser,\r\n }\r\n : null;\r\n } catch (e) {\r\n return null;\r\n }\r\n }\r\n\r\n public async inviteTrustedParty(invite: InviteTrustedParty): Promise<void> {\r\n const params = {\r\n responderUsername: invite.party.username,\r\n email: invite.party.email,\r\n message: {\r\n name: invite.party.name,\r\n email: invite.party.email,\r\n message: invite.party.message,\r\n permissions: invite.permissions,\r\n },\r\n contactCard: {\r\n plainOwnerCipherDataJson: null,\r\n plainSharedCipherDataJson: invite.mySharedDetails,\r\n ownerPlainData: {\r\n name: new ContactCardName(invite.mySharedDetails.name),\r\n },\r\n },\r\n };\r\n await this.keyExchangeService.initiateOtk(params);\r\n }\r\n\r\n public async cancelInvitation(inviteId: string): Promise<void> {\r\n await this.lrApollo.mutate({\r\n mutation: CancelTrustedPartyInvitationMutation,\r\n variables: {\r\n input: {\r\n id: inviteId,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async getInvitation(\r\n inviteId: string,\r\n inviteToken: string,\r\n key: string\r\n ): Promise<TrustedPartyInvite> {\r\n const exchange = await this.keyExchangeService.getKeyExchange(inviteId, {\r\n token: inviteToken,\r\n otKeyK: key,\r\n });\r\n\r\n return this.mapInvite(exchange);\r\n }\r\n\r\n public async acceptInvitation(\r\n invite: AcceptTrustedPartyInvite\r\n ): Promise<string> {\r\n const params: RespondOtkInput = {\r\n id: invite.inviteId,\r\n token: invite.inviteToken,\r\n decryptedOtk: invite.decryptedOtk,\r\n initiatorContactCard: null,\r\n responderContactCard: {\r\n plainOwnerCipherDataJson: null,\r\n plainSharedCipherDataJson: invite.mySharedDetails,\r\n ownerPlainData: {\r\n name: new ContactCardName(invite.mySharedDetails.name),\r\n },\r\n },\r\n };\r\n\r\n const { tp } = await this.keyExchangeService.respondOtk(params);\r\n\r\n return tp.id;\r\n }\r\n\r\n public async declineInvitation(\r\n inviteId: string,\r\n inviteToken: string\r\n ): Promise<void> {\r\n await this.lrApollo.mutate({\r\n mutation: DeclineTrustedPartyInvitationMutation,\r\n variables: {\r\n input: {\r\n id: inviteId,\r\n token: inviteToken,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async confirmInvitation(\r\n confirm: ConfirmTrustedPartyInvite\r\n ): Promise<string> {\r\n const { tp } = await this.keyExchangeService.completeOtk(\r\n confirm.inviteId,\r\n confirm.initiatorRootKeyCipher,\r\n confirm.initiatorOneTimePbkCipher,\r\n null\r\n );\r\n return tp.id;\r\n }\r\n\r\n public async removeTrustedParty(partyId: string): Promise<void> {\r\n await this.lrApollo.mutate({\r\n mutation: DeleteTrustedPartyMutation,\r\n variables: {\r\n input: {\r\n id: partyId,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public setCategoryAccessLevel(\r\n categoryId: string,\r\n keyId: string,\r\n trustedParty: TrustedParty,\r\n accessLevel?: AccessLevel\r\n ): Promise<void> {\r\n return accessLevel\r\n ? this.shareDirectory(categoryId, keyId, trustedParty, accessLevel)\r\n : this.unshareDirectory(categoryId, trustedParty.id);\r\n }\r\n\r\n public setRecordAccessLevel(\r\n recordId: string,\r\n keyId: string,\r\n trustedParty: TrustedParty,\r\n accessLevel: AccessLevel\r\n ): Promise<void> {\r\n return accessLevel\r\n ? this.shareDirectory(recordId, keyId, trustedParty, accessLevel)\r\n : this.unshareDirectory(recordId, trustedParty.id);\r\n }\r\n\r\n private async shareDirectory(\r\n directoryId: string,\r\n keyId: string,\r\n trustedParty: TrustedParty,\r\n accessLevel: AccessLevel\r\n ): Promise<void> {\r\n const key = await this.keyGraphService.getKey(keyId);\r\n const wrappingKey = await this.keyGraphService.getKey(\r\n trustedParty.userSharedKey.sharedKey.id\r\n );\r\n const wrappedKey = await this.encryptionService.encrypt(\r\n wrappingKey.jwk,\r\n key.jwk.toJSON(true)\r\n );\r\n\r\n await this.lrApollo.mutate({\r\n mutation: ShareCategoryMutation,\r\n variables: {\r\n input: {\r\n id: directoryId,\r\n tpId: trustedParty.id,\r\n accessRole: accessLevel,\r\n keyId: key.id,\r\n wrappingKeyId: wrappingKey.id,\r\n wrappedKey: JSON.stringify(wrappedKey),\r\n },\r\n },\r\n });\r\n }\r\n\r\n private async unshareDirectory(\r\n directoryId: string,\r\n trustedPartyId: string\r\n ): Promise<void> {\r\n await this.lrApollo.mutate({\r\n mutation: UnshareCategoryMutation,\r\n variables: {\r\n input: {\r\n id: directoryId,\r\n tpId: trustedPartyId,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async mapTrustedParty(tp: any): Promise<TrustedParty> {\r\n try {\r\n const contactCard =\r\n tp.sharedContactCard &&\r\n (await this.sharedContactCardService.decryptTrustedPartyDetails(\r\n tp.sharedContactCard\r\n ));\r\n const myContactCard =\r\n tp.myContactCard &&\r\n (await this.sharedContactCardService.decryptSharedTrustedPartyDetails(\r\n tp.myContactCard\r\n ));\r\n\r\n return {\r\n id: tp.id,\r\n type: TrustedPartyType.User, // TODO: when partners\r\n hasScenarios: !!tp.sharedScenarios.edges.length,\r\n hasSharedVault: !!tp.sharedItems.directories.edges.length,\r\n name: contactCard && contactCard.name && contactCard.name.name,\r\n details: contactCard,\r\n mySharedDetails: myContactCard,\r\n userSharedKey: tp.currentUserSharedKey.userSharedKey,\r\n username: tp.other.username,\r\n features: {\r\n sharedVault: {\r\n hasAccess:\r\n (tp.other.features?.shareVault || ['noaccess'])[0] === 'access',\r\n },\r\n },\r\n };\r\n } catch (e) {\r\n console.error('Failed to decrypt Trusted Party.', e, tp);\r\n return null;\r\n }\r\n }\r\n\r\n private async mapInvite(\r\n exchange: DecryptedKeyExchange\r\n ): Promise<TrustedPartyInvite> {\r\n const contactCard = exchange.contactCard;\r\n const name = exchange.isInitiator\r\n ? exchange.myMessage?.name\r\n : contactCard && contactCard.name && contactCard.name.name;\r\n const email = exchange.isInitiator\r\n ? exchange.myMessage?.email\r\n : (contactCard && contactCard.email) || exchange.responderEmailAddress;\r\n\r\n return {\r\n id: exchange.id,\r\n type: TrustedPartyType.User, // todo when partners\r\n status: (exchange.state as unknown) as TrustedPartyInviteStatus,\r\n token: exchange.token,\r\n tokenExpiry: exchange.tokenExpiryTime,\r\n decryptedOtk: exchange.decryptedOtk,\r\n name,\r\n email,\r\n isSender: exchange.isInitiator,\r\n actionRequired: exchange.isInitiator\r\n ? exchange.initiatorActionRequired\r\n : exchange.responderActionRequired,\r\n rootKeyCipher: exchange.initiatorRootKeyCipher,\r\n pbkCipher: exchange.otk.initiatorOneTimePbkCipher,\r\n isExpired: exchange.isExpired,\r\n details: contactCard,\r\n message: exchange.message,\r\n mySharedDetails: exchange.myContactCard,\r\n mySharedMessage: exchange.myMessage,\r\n };\r\n }\r\n}\r\n","import { PreparedPermissions } from '../api/key-exchange.types';\r\nimport { Key } from '../cryptography/cryptography.types';\r\nimport { SecretShare } from '../cryptography/slip39.service';\r\nimport { TrustedParty } from '../trusted-parties/trusted-party.types';\r\nimport { ApprovalGroup } from './approvals/scenario-approval.types';\r\nimport { Claimant } from './claimants/scenario-claimant.types';\r\nimport { Receiver } from './receivers/scenario-receiver.types';\r\n\r\n// Glossary\r\n// - Subject: the user that the scenario applies to\r\n// - Approver: the user that can approve a scenario\r\n// - Approver sub-assembly: a group of approvers that must reach quorum for the sub-assembly to be considered approved\r\n// - Approver assembly: a group of sub-assemblies that must reach quorum for the assembly to be considered approved\r\n// - Receiver: a user that will receive the released information\r\n// - Claimant: a user that can start the process of release of information\r\n\r\nexport enum ScenarioState {\r\n // Can not be claimed when DISABLED. Scenarios can be created in this state, then\r\n // set to ENABLED once setup is complete.\r\n DISABLED = 'DISABLED',\r\n // Can be claimed when ENABLED. It sits in this state until claimed.\r\n ENABLED = 'ENABLED',\r\n // Claimant has initiated a claim.\r\n CLAIMED = 'CLAIMED',\r\n // Approvers have approved this scenario\r\n APPROVED = 'APPROVED',\r\n REJECTED = 'REJECTED',\r\n}\r\n\r\nexport enum ScenarioClaimState {\r\n Claimed = 'CLAIMED',\r\n Approved = 'APPROVED',\r\n Expired = 'EXPIRED',\r\n Rejected = 'REJECTED',\r\n Cancelled = 'CANCELLED',\r\n Reset = 'RESET',\r\n}\r\n\r\nexport enum ApproverClaimState {\r\n Claimed = 'CLAIMED',\r\n Approved = 'APPROVED',\r\n Rejected = 'REJECTED',\r\n}\r\n\r\nexport class NewScenario {\r\n name: string;\r\n event: string;\r\n claimants: NewScenarioClaimant[];\r\n approvalGroups: NewScenarioApprovalGroup[];\r\n receivers: NewScenarioReceiver[];\r\n}\r\n\r\nexport class NewScenarioClaimant {\r\n trustedPartyId: string;\r\n trustedPartySharedKeyId: string;\r\n message?: string;\r\n}\r\n\r\nexport class NewScenarioApprovalGroup {\r\n name: string;\r\n quorum: number;\r\n singleReject: boolean;\r\n approvers: NewScenarioApprover[];\r\n}\r\n\r\nexport class NewScenarioApprover {\r\n trustedPartyId: string;\r\n trustedPartySharedKeyId: string;\r\n message?: string;\r\n}\r\n\r\nexport class NewScenarioReceiver {\r\n trustedPartyId: string;\r\n trustedPartySharedKeyId: string;\r\n permissions: PreparedPermissions;\r\n message?: string;\r\n}\r\n\r\nexport class UpdateScenario {\r\n scenarioId: string;\r\n keyId: string;\r\n assemblyKeyId: string;\r\n name: string;\r\n event: string;\r\n claimants: UpdatedScenarioClaimant[];\r\n deletedClaimantIds: string[];\r\n approvalGroups: UpdatedScenarioApprovalGroup[];\r\n deletedGroupIds: string[];\r\n receivers: UpdatedScenarioReceiver[];\r\n deletedReceiverIds: string[];\r\n}\r\n\r\nexport class UpdatedScenarioClaimant {\r\n claimantId?: string;\r\n keyId?: string;\r\n trustedPartyId: string;\r\n trustedPartySharedKeyId: string;\r\n message?: string;\r\n}\r\n\r\nexport class UpdatedScenarioApprovalGroup {\r\n subAssemblyId?: string;\r\n name: string;\r\n quorum: number;\r\n singleReject: boolean;\r\n approvers: UpdatedScenarioApprover[];\r\n deletedApproverIds: string[];\r\n}\r\n\r\nexport class UpdatedScenarioApprover {\r\n approverId?: string;\r\n keyId?: string;\r\n trustedPartyId: string;\r\n trustedPartySharedKeyId: string;\r\n message?: string;\r\n}\r\n\r\nexport class UpdatedScenarioReceiver {\r\n receiverId?: string;\r\n keyId?: string;\r\n trustedPartyId: string;\r\n trustedPartySharedKeyId: string;\r\n permissions: PreparedPermissions;\r\n message?: string;\r\n}\r\n\r\nexport class ScenarioSummary {\r\n id: string;\r\n status: ScenarioState;\r\n name: string;\r\n event: string;\r\n claimId?: string;\r\n claimStatus?: ScenarioClaimState;\r\n createdOn: string | Date;\r\n lastModified: string | Date;\r\n}\r\n\r\nexport class ScenarioClaim {\r\n id: string;\r\n state: ScenarioClaimState;\r\n triggeredBy: TrustedParty;\r\n triggeredOn: string;\r\n lastModified: string;\r\n scenario: ScenarioSummary;\r\n}\r\n\r\nexport class SharedScenarioSummary {\r\n id: string;\r\n status: ScenarioState;\r\n event: string;\r\n\r\n trustedParty: TrustedParty;\r\n claimStatus?: ScenarioClaimState;\r\n}\r\n\r\nexport class SharedScenario {\r\n id: string;\r\n status: ScenarioState;\r\n event: string;\r\n\r\n trustedParty: TrustedParty;\r\n isClaimant: boolean;\r\n claimantMessage?: string;\r\n isApprover: boolean;\r\n approverMessages?: string[];\r\n isReceiver: boolean;\r\n receiverMessage?: string;\r\n receiverKeyId?: string;\r\n receiverPbkId?: string;\r\n receiverDirectories?: { id: string; wrappedItemKey: string }[];\r\n\r\n claim?: SharedScenarioClaim;\r\n}\r\n\r\nexport interface SharedScenarioClaim {\r\n id: string;\r\n isClaimant: boolean;\r\n status: ScenarioClaimState;\r\n asApprovers?: SharedScenarioClaimApprover[];\r\n asReceiver?: {\r\n received: boolean;\r\n ciphers: string[];\r\n };\r\n}\r\n\r\nexport interface SharedScenarioClaimApprover {\r\n approverId: string;\r\n approverKey: string;\r\n status: ApproverClaimState;\r\n receivers: {\r\n id: string;\r\n pbkId: string;\r\n }[];\r\n}\r\n\r\nexport interface Scenario {\r\n id: string;\r\n keyId: string;\r\n assemblyKeyId: string;\r\n assemblyQuorum: number;\r\n status: ScenarioState;\r\n name: string;\r\n event: string;\r\n claimants: Claimant[];\r\n approverGroups: ApprovalGroup[];\r\n receivers: Receiver[];\r\n claim: {\r\n id: string;\r\n status: ScenarioClaimState;\r\n claimant: Claimant;\r\n };\r\n}\r\n\r\nexport interface CreateScenarioInput {\r\n plainSubjectCipherData: object;\r\n}\r\n\r\nexport interface UpdateScenarioInput {\r\n scenarioId: string;\r\n keyId: string;\r\n plainSubjectCipherData: object;\r\n}\r\n\r\nexport interface PartialAssemblyKey {\r\n slip39: {\r\n share: SecretShare;\r\n // Mainly for debugging.\r\n subAssembly: {\r\n quorum: number;\r\n size: number;\r\n };\r\n };\r\n assemblyKeyParams: object;\r\n}\r\n\r\nexport interface SharedClaimReceiver {\r\n id: string;\r\n pbk: Key;\r\n}\r\n\r\nexport interface SharedClaimApprover {\r\n receivers: {\r\n id: string;\r\n pbk: Key;\r\n }[];\r\n}\r\n\r\nexport interface SharedClaimApproval {\r\n receiverPbkCipher: string;\r\n plainReceiverPbkCipher: {\r\n partialAssemblyKey: PartialAssemblyKey;\r\n };\r\n}\r\n\r\nexport interface SharedClaimReceiver {\r\n received: boolean;\r\n approvals: SharedClaimApproval[];\r\n}\r\n","import gql from 'graphql-tag';\r\nimport { KeyGraphField } from '../../_common/queries.gql';\r\nimport { TrustedPartyProperties } from '../../trusted-parties/trusted-party.gql';\r\n\r\nexport const ClaimantFields = `\r\nid\r\ntp {\r\n ${TrustedPartyProperties}\r\n}\r\nsharedKey {\r\n id\r\n}\r\nsharedCipherData\r\n`;\r\n\r\nexport const GetScenarioClaimantQuery = gql`\r\nquery GetScenarioClaimantQuery(\r\n $id: LrRelayIdInput!\r\n) {\r\n scenarioClaimant(id: $id) {\r\n ${ClaimantFields}\r\n }\r\n ${KeyGraphField}\r\n}`;\r\n\r\nexport const AddScenarioClaimantMutation = gql`\r\n mutation AddScenarioClaimantMutation($input: AddScenarioClaimantInput!) {\r\n addScenarioClaimant(input: $input) {\r\n claimant {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UpdateScenarioClaimantMutation = gql`\r\n mutation UpdateScenarioClaimantMutation(\r\n $input: UpdateScenarioClaimantInput!\r\n ) {\r\n updateScenarioClaimant(input: $input) {\r\n claimant {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const DeleteScenarioClaimantMutation = gql`\r\n mutation DeleteScenarioClaimantMutation(\r\n $input: DeleteScenarioClaimantInput!\r\n ) {\r\n deleteScenarioClaimant(input: $input) {\r\n id\r\n }\r\n }\r\n`;\r\n","import gql from 'graphql-tag';\r\nimport { KeyGraphField } from '../../_common/queries.gql';\r\nimport { TrustedPartyProperties } from '../../trusted-parties/trusted-party.gql';\r\nimport { CategoryFields, AccessFields } from '../../category/category.gql';\r\n\r\nexport const ReceiverFields = `\r\n id\r\n tp {\r\n ${TrustedPartyProperties}\r\n }\r\n pbk {\r\n id\r\n }\r\n sharedKey {\r\n id\r\n }\r\n sharedCipherData\r\n categories: receiverDirectories(plainMeta: $categoryFilter, orderBy: \"created\") {\r\n edges {\r\n node {\r\n id\r\n sharedKey {\r\n id\r\n }\r\n sharedCipherData\r\n accessRole\r\n wrappedItemKey\r\n directory {\r\n ${CategoryFields}\r\n }\r\n }\r\n }\r\n }\r\n records: receiverDirectories(plainMeta: $recordFilter, orderBy: \"created\") {\r\n edges {\r\n node {\r\n id\r\n sharedKey {\r\n id\r\n }\r\n sharedCipherData\r\n accessRole\r\n wrappedItemKey\r\n directory {\r\n id\r\n keyId\r\n archived\r\n plainMeta\r\n cipherMeta\r\n created\r\n modified\r\n ${AccessFields}\r\n content: childFileLinks(plainMeta: $contentFilter) {\r\n edges {\r\n node {\r\n childFile {\r\n id\r\n archived\r\n currentVersion {\r\n state {\r\n keyId\r\n plainMeta\r\n cipherMeta\r\n created\r\n modified\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const GetScenarioReceiverQuery = gql`\r\nquery GetScenarioReceiverQuery(\r\n $id: LrRelayIdInput!,\r\n $categoryFilter: LrJSONFilter!,\r\n $recordFilter: LrJSONFilter!,\r\n $contentFilter: LrJSONFilter\r\n) {\r\n scenarioReceiver(id: $id) {\r\n ${ReceiverFields}\r\n }\r\n ${KeyGraphField}\r\n} `;\r\n\r\nexport const CreateScenarioReceiverMutation = gql`\r\n mutation CreateScenarioReceiverMutation(\r\n $input: CreateScenarioReceiverInput!\r\n ) {\r\n createScenarioReceiver(input: $input) {\r\n receiver {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UpdateScenarioReceiverMutation = gql`\r\n mutation UpdateScenarioReceiverMutation(\r\n $input: UpdateScenarioReceiverInput!\r\n ) {\r\n updateScenarioReceiver(input: $input) {\r\n receiver {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const DeleteScenarioReceiverMutation = gql`\r\n mutation DeleteScenarioReceiverMutation(\r\n $input: DeleteScenarioReceiverInput!\r\n ) {\r\n deleteScenarioReceiver(input: $input) {\r\n id\r\n }\r\n }\r\n`;\r\n\r\nexport const AddScenarioReceiverDirectoryMutation = gql`\r\n mutation AddScenarioReceiverDirectoryMutation(\r\n $input: AddScenarioReceiverDirectoryInput!\r\n ) {\r\n addScenarioReceiverDirectory(input: $input) {\r\n receiverDirectory {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UpdateScenarioReceiverDirectoryMutation = gql`\r\n mutation UpdateScenarioReceiverDirectoryMutation(\r\n $input: UpdateScenarioReceiverDirectoryInput!\r\n ) {\r\n updateScenarioReceiverDirectory(input: $input) {\r\n receiverDirectory {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const DeleteScenarioReceiverDirectoryMutation = gql`\r\n mutation DeleteScenarioReceiverDirectoryMutation(\r\n $input: DeleteScenarioReceiverDirectoryInput!\r\n ) {\r\n deleteScenarioReceiverDirectory(input: $input) {\r\n id\r\n }\r\n }\r\n`;\r\n","import gql from 'graphql-tag';\r\nimport { TrustedPartyProperties } from '../../trusted-parties/trusted-party.gql';\r\nimport { KeyGraphField, FetchKeyGraphField } from '../../_common/queries.gql';\r\n\r\nconst ApproverFields = `\r\nid\r\ntp {\r\n ${TrustedPartyProperties}\r\n}\r\nsharedKey {\r\n id\r\n}\r\nsharedCipherData\r\nsharedCipherApprovalData\r\nsharedCipherPartialAssemblyKey\r\n`;\r\n\r\nexport const SubAssemblyFields = `\r\nid\r\nsingleReject\r\nquorum\r\nassemblyKey {\r\n id\r\n}\r\nsubAssemblyCipherData\r\napproverCount\r\napprovers {\r\n edges {\r\n node {\r\n ${ApproverFields}\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport const CreateScenarioApproverAssemblyMutation = gql`\r\nmutation CreateScenarioApproverAssemblyMutation(\r\n $input: CreateScenarioApproverAssemblyInput!\r\n) {\r\n createScenarioApproverAssembly(input: $input) {\r\n scenario {\r\n approverAssembly {\r\n assemblyKey {\r\n id\r\n }\r\n }\r\n }\r\n }\r\n ${FetchKeyGraphField}\r\n}`;\r\n\r\nexport const UpdateScenarioApproverAssemblyMutation = gql`\r\n mutation UpdateScenarioApproverAssemblyMutation(\r\n $input: UpdateScenarioApproverAssemblyInput!\r\n ) {\r\n updateScenarioApproverAssembly(input: $input) {\r\n scenario {\r\n id\r\n }\r\n createdSubAssemblies {\r\n id\r\n }\r\n createdApprovers {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const DeleteScenarioApproverAssemblyMutation = gql`\r\n mutation DeleteScenarioApproverAssemblyMutation(\r\n $input: DeleteScenarioApproverAssemblyInput!\r\n ) {\r\n deleteScenarioApproverAssembly(input: $input) {\r\n scenario {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const GetScenarioApproverQuery = gql`\r\nquery GetScenarioApproverQuery(\r\n $id: LrRelayIdInput!\r\n) {\r\n scenarioApprover(id: $id) {\r\n ${ApproverFields}\r\n }\r\n ${KeyGraphField}\r\n} `;\r\n\r\nexport const AddScenarioApproverMutation = gql`\r\n mutation AddScenarioApproverMutation($input: AddScenarioApproverInput!) {\r\n addScenarioApprover(input: $input) {\r\n approver {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UpdateScenarioApproverMutation = gql`\r\n mutation UpdateScenarioApproverMutation(\r\n $input: UpdateScenarioApproverInput!\r\n ) {\r\n updateScenarioApprover(input: $input) {\r\n approver {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n","import gql from 'graphql-tag';\r\nimport { TrustedPartyProperties } from '../trusted-parties/trusted-party.gql';\r\nimport { KeyGraphField } from '../_common/queries.gql';\r\nimport { ClaimantFields } from './claimants/scenario-claimant.gql';\r\nimport { ReceiverFields } from './receivers/scenario-receiver.gql';\r\nimport { SubAssemblyFields } from './approvals/scenario-approval.gql';\r\nimport { gqlTyped } from '../_common/ast';\r\nimport { ID } from '../api/types';\r\n\r\nconst ApproverFields = `\r\n id\r\n sharedKey {\r\n id\r\n }\r\n sharedCipherData\r\n sharedCipherPartialAssemblyKey\r\n`;\r\n\r\nconst SharedClaimFields = `\r\nid\r\nstate\r\nisClaimant\r\nasClaimApprovers {\r\n edges {\r\n node {\r\n state\r\n approver {\r\n ${ApproverFields}\r\n }\r\n receivers {\r\n edges {\r\n node {\r\n id\r\n pbk {\r\n id\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\nasClaimReceiver {\r\n received\r\n approvals {\r\n edges {\r\n node {\r\n receiverPbkCipher\r\n }\r\n }\r\n }\r\n}\r\n`;\r\n\r\nconst SharedScenarioFields = `\r\nid\r\nstate\r\ntp {\r\n ${TrustedPartyProperties}\r\n}\r\nasClaimant {\r\n sharedKey {\r\n id\r\n }\r\n sharedCipherData\r\n}\r\nasReceiver {\r\n sharedKey {\r\n id\r\n }\r\n sharedCipherData\r\n pbk {\r\n id\r\n }\r\n receiverDirectories {\r\n edges {\r\n node {\r\n id\r\n wrappedItemKey\r\n }\r\n }\r\n }\r\n}\r\nasApprovers {\r\n edges {\r\n node {\r\n ${ApproverFields}\r\n }\r\n }\r\n}\r\nsharedClaim {\r\n ${SharedClaimFields}\r\n}\r\n`;\r\n\r\nexport const GetSharedScenarioQuery = gql`\r\nquery GetSharedScenarioQuery(\r\n $id: LrRelayIdInput!\r\n) {\r\n sharedScenario(id: $id) {\r\n ${SharedScenarioFields}\r\n }\r\n ${KeyGraphField}\r\n} `;\r\n\r\nexport const GetAllSharedScenariosQuery = gql`\r\nquery GetAllSharedScenariosQuery {\r\n sharedScenarios(orderBy: \"-created\") {\r\n edges {\r\n node {\r\n ${SharedScenarioFields}\r\n }\r\n }\r\n }\r\n ${KeyGraphField}\r\n} `;\r\n\r\nexport const GetTrustedPartyScenariosQuery = gql`\r\nquery GetTrustedPartyScenariosQuery($partyId: LrRelayIdInput!) {\r\n tp(id: $partyId) {\r\n myScenarios(orderBy: \"-created\") {\r\n edges {\r\n node {\r\n id\r\n state\r\n subjectKey {\r\n id\r\n }\r\n subjectCipherData\r\n created\r\n modified\r\n }\r\n }\r\n }\r\n sharedScenarios(orderBy: \"-created\") {\r\n edges {\r\n node {\r\n ${SharedScenarioFields}\r\n }\r\n }\r\n }\r\n }\r\n ${KeyGraphField}\r\n} `;\r\n\r\nexport const GetAllScenarioIdsQuery = gql`\r\n query GetAllScenarioIdsQuery {\r\n scenarios {\r\n edges {\r\n node {\r\n id\r\n }\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const GetAllScenariosQuery = gql`\r\nquery GetAllScenariosQuery {\r\n scenarios(orderBy: \"-created\") {\r\n edges {\r\n node {\r\n id\r\n state\r\n subjectKey {\r\n id\r\n }\r\n subjectCipherData\r\n created\r\n modified\r\n claim {\r\n id\r\n state\r\n }\r\n }\r\n }\r\n }\r\n ${KeyGraphField}\r\n} `;\r\n\r\nexport const GetScenarioQuery = gql`\r\nquery GetScenarioQuery(\r\n $id: LrRelayIdInput!,\r\n $categoryFilter: LrJSONFilter!,\r\n $recordFilter: LrJSONFilter!,\r\n $contentFilter: LrJSONFilter\r\n) {\r\n scenario(id: $id) {\r\n id\r\n state\r\n subjectKey {\r\n id\r\n }\r\n subjectCipherData\r\n claimants {\r\n edges {\r\n node {\r\n ${ClaimantFields}\r\n }\r\n }\r\n }\r\n approverAssembly {\r\n id\r\n quorum\r\n assemblyKey {\r\n id\r\n }\r\n subAssemblies {\r\n edges {\r\n node {\r\n ${SubAssemblyFields}\r\n }\r\n }\r\n }\r\n }\r\n receivers {\r\n edges {\r\n node {\r\n ${ReceiverFields}\r\n }\r\n }\r\n }\r\n claim {\r\n id\r\n state\r\n claimant {\r\n id\r\n }\r\n }\r\n }\r\n ${KeyGraphField}\r\n} `;\r\n\r\nexport const GetAllScenarioClaimsQuery = gql`\r\nquery GetAllScenariosQuery {\r\n scenarios {\r\n edges {\r\n node {\r\n id\r\n state\r\n subjectKey {\r\n id\r\n }\r\n subjectCipherData\r\n created\r\n modified\r\n claim {\r\n id\r\n state\r\n }\r\n claims {\r\n edges {\r\n node {\r\n id\r\n state\r\n created\r\n modified\r\n claimant {\r\n tp {\r\n ${TrustedPartyProperties}\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n ${KeyGraphField}\r\n} `;\r\n\r\nexport const CreateScenarioMutation = gql`\r\n mutation CreateScenarioMutation($input: CreateScenarioInput!) {\r\n createScenario(input: $input) {\r\n scenario {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UpdateScenarioMutation = gql`\r\n mutation UpdateScenarioMutation($input: UpdateScenarioInput!) {\r\n updateScenario(input: $input) {\r\n scenario {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const DeleteScenarioMutation = gql`\r\n mutation DeleteScenarioMutation($input: DeleteScenarioInput!) {\r\n deleteScenario(input: $input) {\r\n id\r\n }\r\n }\r\n`;\r\n\r\nexport const EnableScenarioMutation = gql`\r\n mutation EnableScenarioMutation($input: EnableScenarioInput!) {\r\n enableScenario(input: $input) {\r\n scenario {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const DisableScenarioMutation = gql`\r\n mutation DisableScenarioMutation($input: DisableScenarioInput!) {\r\n disableScenario(input: $input) {\r\n scenario {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const CreateScenarioClaimMutation = gql`\r\n mutation CreateScenarioClaimMutation($input: CreateScenarioClaimInput!) {\r\n createScenarioClaim(input: $input) {\r\n sharedClaim {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const CancelScenarioClaimMutation = gql`\r\n mutation CancelScenarioClaimMutation($input: CancelScenarioClaimInput!) {\r\n cancelScenarioClaim(input: $input) {\r\n sharedClaim {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport interface ApproveScenarioClaimMutationResult {\r\n approveScenarioClaim: {\r\n sharedClaim: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const ApproveScenarioClaimMutation = gqlTyped<ApproveScenarioClaimMutationResult>`\r\nmutation ApproveScenarioClaimMutation($input: ApproveScenarioClaimInput!) {\r\n approveScenarioClaim(input: $input) {\r\n sharedClaim {\r\n id\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport interface RejectScenarioClaimMutationResult {\r\n rejectScenarioClaim: {\r\n sharedClaim: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const RejectScenarioClaimMutation = gqlTyped<RejectScenarioClaimMutationResult>`\r\nmutation RejectScenarioClaimMutation($input: RejectScenarioClaimInput!) {\r\n rejectScenarioClaim(input: $input) {\r\n sharedClaim {\r\n id\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport const ReceiveScenarioClaimMutation = gql`\r\n mutation ReceiveScenarioClaimMutation($input: ReceiveScenarioClaimInput!) {\r\n receiveScenarioClaim(input: $input) {\r\n sharedClaim {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const ResetScenarioMutation = gql`\r\n mutation ResetScenarioMutation($input: ResetScenarioInput!) {\r\n resetScenario(input: $input) {\r\n scenario {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport const UpdateScenarioApproverSubAssemblyMutation = gql`\r\n mutation UpdateScenarioApproverSubAssemblyMutation(\r\n $input: UpdateScenarioApproverSubAssemblyInput!\r\n ) {\r\n updateScenarioApproverSubAssembly(input: $input) {\r\n subAssembly {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n","import { Injectable } from '@angular/core';\r\nimport { JWK } from 'node-jose';\r\nimport { LrApolloService } from '../../api/lr-apollo.service';\r\nimport { EncryptionService } from '../../cryptography/encryption.service';\r\nimport { KeyFactoryService } from '../../cryptography/key-factory.service';\r\nimport { KeyGraphService } from '../../cryptography/key-graph.service';\r\nimport { KeyMetaService } from '../../cryptography/key-meta.service';\r\nimport * as slip from '../../cryptography/slip39.service';\r\nimport { TrustedPartyService } from '../../trusted-parties/trusted-party.service';\r\nimport {\r\n Receiver,\r\n ReceiverCategory,\r\n ReceiverRecord,\r\n} from '../receivers/scenario-receiver.types';\r\nimport { PartialAssemblyKey } from '../scenario.types';\r\nimport {\r\n CreateScenarioApproverAssemblyMutation,\r\n DeleteScenarioApproverAssemblyMutation,\r\n GetScenarioApproverQuery,\r\n UpdateScenarioApproverAssemblyMutation,\r\n UpdateScenarioApproverMutation,\r\n} from './scenario-approval.gql';\r\nimport {\r\n ApprovalGroup,\r\n Approver,\r\n CreateScenarioApprovalGroups,\r\n UpdateScenarioApprovalGroup,\r\n UpdateScenarioApprovalGroups,\r\n UpdateScenarioApprover,\r\n} from './scenario-approval.types';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class ScenarioApproverService {\r\n public static SLIP39_PASSPHRASE = 'lifeready';\r\n\r\n constructor(\r\n private lrApollo: LrApolloService,\r\n private keyFactory: KeyFactoryService,\r\n private keyMetaService: KeyMetaService,\r\n private keyGraph: KeyGraphService,\r\n private slip39Service: slip.Slip39Service,\r\n private encryptionService: EncryptionService,\r\n private trustedPartyService: TrustedPartyService\r\n ) {}\r\n\r\n public async getApprover(approverId: string): Promise<Approver> {\r\n const { scenarioApprover } = await this.lrApollo.query<any>({\r\n query: GetScenarioApproverQuery,\r\n variables: {\r\n id: approverId,\r\n },\r\n });\r\n return this.mapApprover(scenarioApprover);\r\n }\r\n\r\n public async mapApproverGroup(group: any): Promise<ApprovalGroup> {\r\n const { name } = await this.keyGraph.decryptFromString<{\r\n name: string;\r\n }>(group.assemblyKey.id, group.subAssemblyCipherData);\r\n\r\n return {\r\n id: group.id,\r\n keyId: group.assemblyKey.id,\r\n name,\r\n quorum: group.quorum,\r\n singleReject: group.singleReject,\r\n approvers: await Promise.all(\r\n group.approvers.edges.map((x) => this.mapApprover(x.node))\r\n ),\r\n };\r\n }\r\n\r\n private async mapApprover(approver: any): Promise<Approver> {\r\n const { message } = await this.keyGraph.decryptFromString<{\r\n message: string;\r\n }>(approver.sharedKey.id, approver.sharedCipherData);\r\n\r\n return {\r\n id: approver.id,\r\n keyId: approver.sharedKey.id,\r\n trustedParty: await this.trustedPartyService.mapTrustedParty(approver.tp),\r\n message,\r\n };\r\n }\r\n\r\n public async updateApprover(approver: UpdateScenarioApprover): Promise<void> {\r\n const sharedCipherData = await this.keyGraph.encryptToString(\r\n approver.keyId,\r\n approver.plainSharedCipherData\r\n );\r\n\r\n await this.lrApollo.mutate<any>({\r\n mutation: UpdateScenarioApproverMutation,\r\n variables: {\r\n input: {\r\n approverId: approver.approverId,\r\n sharedKeyId: approver.keyId,\r\n sharedCipherData,\r\n sharedCipherApprovalData: '',\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async createScenarioApproverAssembly(\r\n input: CreateScenarioApprovalGroups\r\n ): Promise<string> {\r\n const assemblyKey = await this.keyFactory.createKey();\r\n\r\n const subjectKeyWrappedAssemblyKey = await this.keyGraph.encryptToString(\r\n input.keyId,\r\n assemblyKey.toJSON(true)\r\n );\r\n\r\n const assemblyCipherData = input.plainAssemblyCipherData\r\n ? await this.keyGraph.encryptToString(\r\n assemblyKey,\r\n input.plainAssemblyCipherData\r\n )\r\n : '';\r\n\r\n const { createScenarioApproverAssembly } = await this.lrApollo.mutate<any>({\r\n mutation: CreateScenarioApproverAssemblyMutation,\r\n variables: {\r\n input: {\r\n scenarioId: input.scenarioId,\r\n singleReject: input.singleReject,\r\n quorum: input.quorum,\r\n subjectKeyId: input.keyId,\r\n subjectKeyWrappedAssemblyKey,\r\n assemblyCipherData,\r\n createSubAssemblies: (\r\n await this.mapApprovalGroups(\r\n input.approvalGroups,\r\n input.quorum,\r\n assemblyKey\r\n )\r\n ).map((x) => {\r\n const { updateApprovers, deleteApprovers, ...subAssembly } = x;\r\n return subAssembly;\r\n }),\r\n updateReceivers: await this.rewrapReceivers(\r\n assemblyKey,\r\n input.event,\r\n input.receivers\r\n ),\r\n },\r\n },\r\n });\r\n return createScenarioApproverAssembly.scenario.approverAssembly.assemblyKey\r\n .id;\r\n }\r\n\r\n public async updateScenarioApproverAssembly(\r\n input: UpdateScenarioApprovalGroups\r\n ): Promise<void> {\r\n const assemblyKey = await this.keyGraph.getKey(input.assemblyKeyId);\r\n const assemblyCipherData = input.plainAssemblyCipherData\r\n ? await this.keyGraph.encryptToString(\r\n assemblyKey.jwk,\r\n input.plainAssemblyCipherData\r\n )\r\n : '';\r\n\r\n const approvalGroups = await this.mapApprovalGroups(\r\n input.approvalGroups,\r\n input.quorum,\r\n assemblyKey.jwk\r\n );\r\n\r\n await this.lrApollo.mutate<any>({\r\n mutation: UpdateScenarioApproverAssemblyMutation,\r\n variables: {\r\n input: {\r\n scenarioId: input.scenarioId,\r\n singleReject: input.singleReject,\r\n quorum: input.quorum,\r\n assemblyKeyId: assemblyKey.id,\r\n assemblyCipherData,\r\n createSubAssemblies: approvalGroups\r\n .filter((x) => !x.subAssemblyId)\r\n .map((x) => {\r\n const { updateApprovers, deleteApprovers, ...subAssembly } = x;\r\n return subAssembly;\r\n }),\r\n updateSubAssemblies: approvalGroups.filter((x) => x.subAssemblyId),\r\n deleteSubAssemblies: input.deletedGroupIds,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async deleteScenarioApproverAssembly(\r\n scenarioId: string,\r\n event: string,\r\n receivers: Receiver[]\r\n ): Promise<void> {\r\n await this.lrApollo.mutate<any>({\r\n mutation: DeleteScenarioApproverAssemblyMutation,\r\n variables: {\r\n input: {\r\n scenarioId,\r\n updateReceivers: await this.rewrapReceivers(null, event, receivers),\r\n },\r\n },\r\n });\r\n }\r\n\r\n private async rewrapReceivers(\r\n assemblyKey: JWK.Key,\r\n event: string,\r\n receivers: Receiver[]\r\n ) {\r\n if (!receivers || !receivers.length) {\r\n return [];\r\n }\r\n\r\n return await Promise.all(\r\n receivers.map(async (receiver) => {\r\n const sharedKey = await this.keyGraph.getKey(receiver.keyId);\r\n\r\n const prepareReceiverItem = async (\r\n item: ReceiverCategory | ReceiverRecord,\r\n itemKeyId: string\r\n ) => {\r\n const itemKey = await this.keyGraph.getKey(itemKeyId);\r\n let wrappedItemKey = await this.keyGraph.encryptToString(\r\n sharedKey.jwk,\r\n itemKey.jwk.toJSON(true)\r\n );\r\n\r\n if (assemblyKey) {\r\n wrappedItemKey = await this.keyGraph.encryptToString(\r\n assemblyKey,\r\n wrappedItemKey\r\n );\r\n }\r\n\r\n return {\r\n accessRole: item.accessLevel,\r\n sharedKeyId: sharedKey.id,\r\n sharedCipherData: '',\r\n wrappedItemKey,\r\n };\r\n };\r\n\r\n // For each receiver-directory\r\n const receiverDirectories = await Promise.all([\r\n ...receiver.categories.map(async (x) => ({\r\n ...(await prepareReceiverItem(x, x.category.keyId)),\r\n receiverDirectoryId: x.id,\r\n })),\r\n ...receiver.records.map(async (x) => ({\r\n ...(await prepareReceiverItem(x, x.record.keyId)),\r\n receiverDirectoryId: x.id,\r\n })),\r\n ]);\r\n\r\n return {\r\n receiverId: receiver.id,\r\n sharedKeyId: receiver.keyId,\r\n receiverDirectories,\r\n receiverFiles: [],\r\n sharedCipherData: await this.keyGraph.encryptToString(sharedKey.jwk, {\r\n event,\r\n message: receiver.message,\r\n }),\r\n };\r\n })\r\n );\r\n }\r\n\r\n private async mapApprovalGroups(\r\n approvalGroups: UpdateScenarioApprovalGroup[],\r\n quorum: number,\r\n assemblyKey: JWK.Key\r\n ) {\r\n const slipAssembly = await this.createSlipAssembly(\r\n quorum,\r\n approvalGroups,\r\n (assemblyKey.toJSON(true) as any).k\r\n );\r\n return await Promise.all(\r\n approvalGroups.map((x, index) =>\r\n this.mapApprovalGroup(x, slipAssembly.subAssemblies[index], assemblyKey)\r\n )\r\n );\r\n }\r\n\r\n private async mapApprovalGroup(\r\n approvalGroup: UpdateScenarioApprovalGroup,\r\n subAssembly: slip.SubAssembly,\r\n assemblyKey: JWK.Key\r\n ) {\r\n const approvers = await this.mapApprovers(\r\n approvalGroup.approvers,\r\n approvalGroup.quorum,\r\n subAssembly,\r\n assemblyKey\r\n );\r\n\r\n return {\r\n subAssemblyId: approvalGroup.subAssemblyId,\r\n singleReject: approvalGroup.singleReject,\r\n quorum: approvalGroup.quorum,\r\n subAssemblyCipherData: await this.keyGraph.encryptToString(\r\n assemblyKey,\r\n approvalGroup.plainSubAssemblyCipherData\r\n ),\r\n createApprovers: approvers.filter((x) => !x.approverId),\r\n updateApprovers: approvers.filter((x) => x.approverId),\r\n deleteApprovers: approvalGroup.deletedApproverIds || [],\r\n };\r\n }\r\n\r\n private async mapApprovers(\r\n approvers: UpdateScenarioApprover[],\r\n quorum: number,\r\n subAssembly: slip.SubAssembly,\r\n assemblyKey: JWK.Key\r\n ) {\r\n const { k: rawAssemblyKey, ...assemblyKeyParams } = assemblyKey.toJSON(\r\n true\r\n ) as any;\r\n let shareIdx = 0;\r\n\r\n const nextPartialAssemblyKey = async (sharedKeyJwk: JWK.Key) => {\r\n const share = subAssembly.shares[shareIdx];\r\n // If quorum is 1, then using the same share for every member.\r\n if (quorum !== 1) {\r\n ++shareIdx;\r\n }\r\n const partialAssemblyKey: PartialAssemblyKey = {\r\n slip39: {\r\n share,\r\n subAssembly: {\r\n quorum,\r\n size: approvers.length,\r\n },\r\n },\r\n assemblyKeyParams,\r\n };\r\n return this.keyGraph.encryptToString(sharedKeyJwk, partialAssemblyKey);\r\n };\r\n\r\n return await Promise.all(\r\n approvers.map(async (x) => {\r\n if (x.approverId) {\r\n const sharedKey = await this.keyGraph.getKey(x.keyId);\r\n const sharedCipherData = await this.keyGraph.encryptToString(\r\n x.keyId,\r\n x.plainSharedCipherData\r\n );\r\n const sharedCipherApprovalData = await this.keyGraph.encryptToString(\r\n x.keyId,\r\n x.approvalData\r\n );\r\n\r\n return {\r\n approverId: x.approverId,\r\n sharedKeyId: x.keyId,\r\n sharedCipherData: sharedCipherData || '',\r\n sharedCipherApprovalData: sharedCipherApprovalData || '',\r\n sharedCipherPartialAssemblyKey: await nextPartialAssemblyKey(\r\n sharedKey.jwk\r\n ),\r\n };\r\n } else {\r\n const wrappedContent = await this.keyMetaService.wrapContentWithKey(\r\n x.plainSharedCipherData,\r\n x.trustedPartySharedKeyId\r\n );\r\n\r\n return {\r\n tpId: x.trustedPartyId,\r\n tpSharedKeyId: x.trustedPartySharedKeyId,\r\n tpSharedKeyWrappedSharedKey: wrappedContent.rootKey.wrappedKey,\r\n sharedCipherData: wrappedContent.cipherMeta,\r\n sharedCipherApprovalData: '',\r\n sharedCipherPartialAssemblyKey: await nextPartialAssemblyKey(\r\n wrappedContent.key\r\n ),\r\n };\r\n }\r\n })\r\n );\r\n }\r\n\r\n // Split assembly key between all existing approvers.\r\n private async createSlipAssembly(\r\n quorum: number,\r\n approvalGroups: UpdateScenarioApprovalGroup[],\r\n rawAssemblyKey: string\r\n ): Promise<slip.Assembly> {\r\n const slipAssembly = new slip.Assembly(quorum);\r\n\r\n approvalGroups.forEach((x, index) => {\r\n let approverCount = x.approvers.length;\r\n\r\n // slip39 restricts quorum == 1 to have only 1 member. So we just share the same\r\n // partial key for all sub assembly members.\r\n if (x.quorum === 1) {\r\n approverCount = 1;\r\n }\r\n slipAssembly.addSubAssembly(\r\n new slip.SubAssembly(index, x.quorum, approverCount)\r\n );\r\n });\r\n // Is there enough sub assemblies to meet quorum\r\n if (slipAssembly.subAssemblies.length < quorum) {\r\n return null;\r\n }\r\n await this.slip39Service.generateShares(\r\n rawAssemblyKey,\r\n ScenarioApproverService.SLIP39_PASSPHRASE,\r\n slipAssembly\r\n );\r\n return slipAssembly;\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport { LrApolloService } from '../../api/lr-apollo.service';\r\nimport { KeyGraphService } from '../../cryptography/key-graph.service';\r\nimport { KeyMetaService } from '../../cryptography/key-meta.service';\r\nimport { TrustedPartyService } from '../../trusted-parties/trusted-party.service';\r\nimport {\r\n DeleteScenarioClaimantMutation,\r\n UpdateScenarioClaimantMutation,\r\n GetScenarioClaimantQuery,\r\n AddScenarioClaimantMutation,\r\n} from './scenario-claimant.gql';\r\nimport {\r\n Claimant,\r\n AddScenarioClaimant,\r\n UpdateScenarioClaimant,\r\n} from './scenario-claimant.types';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class ScenarioClaimantService {\r\n constructor(\r\n private lrApollo: LrApolloService,\r\n private keyMetaService: KeyMetaService,\r\n private keyGraph: KeyGraphService,\r\n private tpService: TrustedPartyService\r\n ) {}\r\n\r\n public async getClaimant(claimantId: string): Promise<Claimant> {\r\n const { scenarioClaimant } = await this.lrApollo.query<any>({\r\n query: GetScenarioClaimantQuery,\r\n variables: {\r\n id: claimantId,\r\n },\r\n });\r\n return this.mapClaimant(scenarioClaimant);\r\n }\r\n\r\n public async mapClaimant(claimant: any): Promise<Claimant> {\r\n const { message } = await this.keyGraph.decryptFromString<{\r\n message: string;\r\n }>(claimant.sharedKey.id, claimant.sharedCipherData);\r\n\r\n return {\r\n id: claimant.id,\r\n keyId: claimant.sharedKey.id,\r\n trustedParty: await this.tpService.mapTrustedParty(claimant.tp),\r\n message,\r\n };\r\n }\r\n\r\n public async addClaimant(claimant: AddScenarioClaimant): Promise<string> {\r\n const wrappedContent = await this.keyMetaService.wrapContentWithKey(\r\n claimant.plainSharedCipherData,\r\n claimant.trustedPartySharedKeyId\r\n );\r\n\r\n const { addScenarioClaimant } = await this.lrApollo.mutate<any>({\r\n mutation: AddScenarioClaimantMutation,\r\n variables: {\r\n input: {\r\n scenarioId: claimant.scenarioId,\r\n tpId: claimant.trustedPartyId,\r\n tpSharedKeyId: claimant.trustedPartySharedKeyId,\r\n tpSharedKeyWrappedSharedKey: wrappedContent.rootKey.wrappedKey,\r\n sharedCipherData: wrappedContent.cipherMeta,\r\n },\r\n },\r\n });\r\n return addScenarioClaimant.claimant.id;\r\n }\r\n\r\n public async updateClaimant(\r\n claimant: UpdateScenarioClaimant\r\n ): Promise<string> {\r\n const sharedCipherData = await this.keyGraph.encryptToString(\r\n claimant.keyId,\r\n claimant.plainSharedCipherData\r\n );\r\n\r\n const res = await this.lrApollo.mutate<any>({\r\n mutation: UpdateScenarioClaimantMutation,\r\n variables: {\r\n input: {\r\n claimantId: claimant.id,\r\n sharedKeyId: claimant.keyId,\r\n sharedCipherData,\r\n },\r\n },\r\n });\r\n return res.updateScenarioClaimant.claimant.id;\r\n }\r\n\r\n public async deleteClaimant(claimantId: string): Promise<void> {\r\n await this.lrApollo.mutate<any>({\r\n mutation: DeleteScenarioClaimantMutation,\r\n variables: { input: { claimantId } },\r\n });\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport { LrApolloService } from '../../api/lr-apollo.service';\r\nimport { CategoryFilter, RecordFilter } from '../../category/category.gql';\r\nimport { CategoryService } from '../../category/category.service';\r\nimport { KeyGraphService } from '../../cryptography/key-graph.service';\r\nimport { KeyMetaService } from '../../cryptography/key-meta.service';\r\nimport { RecordContentFilter } from '../../record/record.gql';\r\nimport { RecordService } from '../../record/record.service';\r\nimport { TrustedPartyService } from '../../trusted-parties/trusted-party.service';\r\nimport { HasEdges } from '../../_common/types';\r\nimport {\r\n AddScenarioReceiverDirectoryMutation,\r\n CreateScenarioReceiverMutation,\r\n DeleteScenarioReceiverDirectoryMutation,\r\n DeleteScenarioReceiverMutation,\r\n GetScenarioReceiverQuery,\r\n UpdateScenarioReceiverDirectoryMutation,\r\n UpdateScenarioReceiverMutation,\r\n} from './scenario-receiver.gql';\r\nimport {\r\n AddScenarioReceiverCategoryInput,\r\n AddScenarioReceiverItemInput,\r\n AddScenarioReceiverRecordInput,\r\n AddScenarioReceiver,\r\n Receiver,\r\n ReceiverCategory,\r\n ReceiverRecord,\r\n UpdateScenarioReceiver,\r\n UpdateScenarioReceiverItemInput,\r\n} from './scenario-receiver.types';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class ScenarioReceiverService {\r\n constructor(\r\n private lrApollo: LrApolloService,\r\n private keyGraph: KeyGraphService,\r\n private keyMetaService: KeyMetaService,\r\n private tpService: TrustedPartyService,\r\n private categoryService: CategoryService,\r\n private recordService: RecordService\r\n ) {}\r\n\r\n public async getReceiver(receiverId: string): Promise<Receiver> {\r\n const { scenarioReceiver } = await this.lrApollo.query<any>({\r\n query: GetScenarioReceiverQuery,\r\n variables: {\r\n id: receiverId,\r\n categoryFilter: CategoryFilter,\r\n recordFilter: RecordFilter,\r\n contentFilter: RecordContentFilter,\r\n },\r\n });\r\n return this.mapReceiver(scenarioReceiver);\r\n }\r\n\r\n public async mapReceiver(receiver: any): Promise<Receiver> {\r\n const { message } = await this.keyGraph.decryptFromString<{\r\n message: string;\r\n }>(receiver.sharedKey.id, receiver.sharedCipherData);\r\n return {\r\n id: receiver.id,\r\n keyId: receiver.sharedKey.id,\r\n trustedParty: await this.tpService.mapTrustedParty(receiver.tp),\r\n message,\r\n categories: await this.mapCategories(receiver.categories),\r\n records: await this.mapRecords(receiver.records),\r\n };\r\n }\r\n\r\n private async mapCategories(list: HasEdges<any>) {\r\n return (\r\n await Promise.all<ReceiverCategory>(\r\n list.edges\r\n .map((x) => x.node)\r\n .map((x) => x.childDirectory || x)\r\n .map((node: any) => this.mapReceiverCategory(node))\r\n )\r\n )\r\n .filter((x) => x)\r\n .sort((x, y) =>\r\n x.category.name === y.category.name\r\n ? 0\r\n : x.category.name > y.category.name\r\n ? 1\r\n : -1\r\n );\r\n }\r\n\r\n private async mapRecords(list: HasEdges<any>) {\r\n return (\r\n await Promise.all<ReceiverRecord>(\r\n list.edges\r\n .map((x) => x.node)\r\n .map((x) => x.childDirectory || x)\r\n .map((node: any) => this.mapReceiverRecord(node))\r\n )\r\n )\r\n .filter((x) => x)\r\n .sort((x, y) =>\r\n x.record.name === y.record.name\r\n ? 0\r\n : x.record.name > y.record.name\r\n ? 1\r\n : -1\r\n );\r\n }\r\n\r\n private async mapReceiverCategory(\r\n receiverDirectory: any\r\n ): Promise<ReceiverCategory> {\r\n return {\r\n id: receiverDirectory.id,\r\n keyId: receiverDirectory.sharedKey.id,\r\n accessLevel: receiverDirectory.accessRole,\r\n category: await this.categoryService.mapCategory(\r\n receiverDirectory.directory\r\n ),\r\n };\r\n }\r\n\r\n private async mapReceiverRecord(\r\n receiverDirectory: any\r\n ): Promise<ReceiverRecord> {\r\n return {\r\n id: receiverDirectory.id,\r\n keyId: receiverDirectory.sharedKey.id,\r\n accessLevel: receiverDirectory.accessRole,\r\n record: await this.categoryService.mapRecord(receiverDirectory.directory),\r\n };\r\n }\r\n\r\n public async addReceiver(receiver: AddScenarioReceiver): Promise<string> {\r\n const wrappedContent = await this.keyMetaService.wrapContentWithKey(\r\n receiver.plainSharedCipherData,\r\n receiver.trustedPartySharedKeyId\r\n );\r\n\r\n const { createScenarioReceiver } = await this.lrApollo.mutate<any>({\r\n mutation: CreateScenarioReceiverMutation,\r\n variables: {\r\n input: {\r\n scenarioId: receiver.scenarioId,\r\n tpId: receiver.trustedPartyId,\r\n tpSharedKeyId: receiver.trustedPartySharedKeyId,\r\n tpSharedKeyWrappedSharedKey: wrappedContent.rootKey.wrappedKey,\r\n sharedCipherData: wrappedContent.cipherMeta,\r\n },\r\n },\r\n });\r\n return createScenarioReceiver.receiver.id;\r\n }\r\n\r\n public async updateReceiver(receiver: UpdateScenarioReceiver): Promise<void> {\r\n const sharedCipherData = await this.keyGraph.encryptToString(\r\n receiver.keyId,\r\n receiver.plainSharedCipherData\r\n );\r\n\r\n await this.lrApollo.mutate<any>({\r\n mutation: UpdateScenarioReceiverMutation,\r\n variables: {\r\n input: {\r\n receiverId: receiver.id,\r\n sharedKeyId: receiver.keyId,\r\n sharedCipherData,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async deleteReceiver(receiverId: string): Promise<void> {\r\n await this.lrApollo.mutate<any>({\r\n mutation: DeleteScenarioReceiverMutation,\r\n variables: { input: { receiverId } },\r\n });\r\n }\r\n\r\n public async addReceiverCategory(\r\n input: AddScenarioReceiverCategoryInput\r\n ): Promise<string> {\r\n const category = await this.categoryService.getCategory(input.categoryId);\r\n\r\n const res = await this.lrApollo.mutate<any>({\r\n mutation: AddScenarioReceiverDirectoryMutation,\r\n variables: {\r\n input: {\r\n ...(await this.addReceiverItem(input, category.category.keyId)),\r\n directoryId: category.category.id,\r\n },\r\n },\r\n });\r\n\r\n return res.addScenarioReceiverDirectory.receiverDirectory.id;\r\n }\r\n\r\n public async addReceiverRecord(\r\n input: AddScenarioReceiverRecordInput\r\n ): Promise<string> {\r\n const record = await this.recordService.getRecord(input.recordId);\r\n\r\n const { addScenarioReceiverDirectory } = await this.lrApollo.mutate<any>({\r\n mutation: AddScenarioReceiverDirectoryMutation,\r\n variables: {\r\n input: {\r\n ...(await this.addReceiverItem(input, record.keyId)),\r\n directoryId: record.id,\r\n },\r\n },\r\n });\r\n return addScenarioReceiverDirectory.receiverDirectory.id;\r\n }\r\n\r\n private async addReceiverItem(\r\n input: AddScenarioReceiverItemInput,\r\n itemKeyId: string\r\n ): Promise<any> {\r\n const sharedCipherData = input.plainSharedCipherData\r\n ? await this.keyGraph.encryptToString(\r\n input.receiverKeyId,\r\n input.plainSharedCipherData\r\n )\r\n : '';\r\n\r\n const itemKey = await this.keyGraph.getKey(itemKeyId);\r\n let wrappedItemKey = await this.keyGraph.encryptToString(\r\n input.receiverKeyId,\r\n itemKey.jwk.toJSON(true)\r\n );\r\n\r\n if (input.assemblyKeyId) {\r\n wrappedItemKey = await this.keyGraph.encryptToString(\r\n input.assemblyKeyId,\r\n wrappedItemKey\r\n );\r\n }\r\n\r\n return {\r\n receiverId: input.receiverId,\r\n sharedKeyId: input.receiverKeyId,\r\n assemblyKeyId: input.assemblyKeyId,\r\n wrappedItemKey,\r\n accessRole: input.accessRole,\r\n sharedCipherData,\r\n };\r\n }\r\n\r\n public async updateReceiverItem(\r\n input: UpdateScenarioReceiverItemInput\r\n ): Promise<void> {\r\n const sharedCipherData = input.plainSharedCipherData\r\n ? await this.keyGraph.encryptToString(\r\n input.keyId,\r\n input.plainSharedCipherData\r\n )\r\n : '';\r\n\r\n await this.lrApollo.mutate<any>({\r\n mutation: UpdateScenarioReceiverDirectoryMutation,\r\n variables: {\r\n input: {\r\n receiverDirectoryId: input.id,\r\n sharedKeyId: input.keyId,\r\n accessRole: input.accessRole,\r\n sharedCipherData,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async deleteReceiverItem(receiverCategoryId: string): Promise<void> {\r\n await this.lrApollo.mutate<any>({\r\n mutation: DeleteScenarioReceiverDirectoryMutation,\r\n variables: { input: { receiverDirectoryId: receiverCategoryId } },\r\n });\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport { JWK } from 'node-jose';\r\nimport { LrApolloService } from '../api/lr-apollo.service';\r\nimport { CategoryFilter, RecordFilter } from '../category/category.gql';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { KeyMetaService } from '../cryptography/key-meta.service';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport * as slip from '../cryptography/slip39.service';\r\nimport { RecordContentFilter } from '../record/record.gql';\r\nimport { TrustedPartyService } from '../trusted-parties/trusted-party.service';\r\nimport {\r\n LrException,\r\n LrErrorCode,\r\n LrBadArgumentException,\r\n} from '../_common/exceptions';\r\nimport { ApprovalGroup, Approver } from './approvals/scenario-approval.types';\r\nimport { ScenarioApproverService } from './approvals/scenario-approver.service';\r\nimport { ScenarioClaimantService } from './claimants/scenario-claimant.service';\r\nimport { Claimant } from './claimants/scenario-claimant.types';\r\nimport { ScenarioReceiverService } from './receivers/scenario-receiver.service';\r\nimport { Receiver } from './receivers/scenario-receiver.types';\r\nimport {\r\n ApproveScenarioClaimMutation,\r\n CancelScenarioClaimMutation,\r\n CreateScenarioClaimMutation,\r\n CreateScenarioMutation,\r\n DeleteScenarioMutation,\r\n DisableScenarioMutation,\r\n EnableScenarioMutation,\r\n GetAllScenarioClaimsQuery,\r\n GetAllScenariosQuery,\r\n GetAllSharedScenariosQuery,\r\n GetScenarioQuery,\r\n GetSharedScenarioQuery,\r\n GetTrustedPartyScenariosQuery,\r\n ReceiveScenarioClaimMutation,\r\n RejectScenarioClaimMutation,\r\n ResetScenarioMutation,\r\n UpdateScenarioMutation,\r\n GetAllScenarioIdsQuery,\r\n} from './scenario.gql';\r\nimport {\r\n CreateScenarioInput,\r\n PartialAssemblyKey,\r\n Scenario,\r\n ScenarioClaim,\r\n ScenarioState,\r\n ScenarioSummary,\r\n SharedScenario,\r\n UpdateScenarioInput,\r\n SharedScenarioClaimApprover,\r\n ApproverClaimState,\r\n SharedScenarioSummary,\r\n} from './scenario.types';\r\nimport * as moment_ from 'moment';\r\nimport { KeyFactoryService as KFS } from '../cryptography/key-factory.service';\r\nimport {\r\n LrGraphQLService,\r\n LrMergedMutation,\r\n LrMutation,\r\n} from '../api/lr-graphql';\r\n\r\n// Ref: https://stackoverflow.com/questions/59735280/angular-8-moment-error-cannot-call-a-namespace-moment\r\nconst moment = moment_;\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class ScenarioService {\r\n constructor(\r\n private lrApollo: LrApolloService,\r\n private keyMetaService: KeyMetaService,\r\n private keyFactory: KFS,\r\n private keyService: KeyService,\r\n private encryptionService: EncryptionService,\r\n private keyGraph: KeyGraphService,\r\n private tpService: TrustedPartyService,\r\n private slip39Service: slip.Slip39Service,\r\n private scenarioClaimantService: ScenarioClaimantService,\r\n private scenarioApproverService: ScenarioApproverService,\r\n private scenarioReceiverService: ScenarioReceiverService,\r\n private lrGraphQL: LrGraphQLService\r\n ) {}\r\n\r\n public async getMyScenarios(): Promise<ScenarioSummary[]> {\r\n const { scenarios } = await this.lrApollo.query<any>({\r\n query: GetAllScenariosQuery,\r\n });\r\n return await Promise.all(\r\n scenarios.edges.map((x: any) => this.mapScenarioSummary(x.node))\r\n );\r\n }\r\n\r\n private async mapScenarioSummary(scenario: any): Promise<ScenarioSummary> {\r\n const { event, name } = await this.keyGraph.decryptFromString<{\r\n event: string;\r\n name: string;\r\n }>(scenario.subjectKey.id, scenario.subjectCipherData);\r\n\r\n return {\r\n id: scenario.id,\r\n name,\r\n event,\r\n status: scenario.state,\r\n claimId: scenario.claim && scenario.claim.id,\r\n claimStatus: scenario.claim && scenario.claim.state,\r\n createdOn: scenario.created,\r\n lastModified: scenario.modified,\r\n };\r\n }\r\n\r\n public async getSharedScenarios(): Promise<SharedScenarioSummary[]> {\r\n const { sharedScenarios } = await this.lrApollo.query<any>({\r\n query: GetAllSharedScenariosQuery,\r\n });\r\n return (\r\n await Promise.all<SharedScenario>(\r\n sharedScenarios.edges.map((x: any) => this.mapSharedScenario(x.node))\r\n )\r\n ).filter((x) => x);\r\n }\r\n\r\n private async mapSharedScenarioSummary(\r\n scenario: any\r\n ): Promise<ScenarioSummary> {\r\n const { event, name } = await this.keyGraph.decryptFromString<{\r\n event: string;\r\n name: string;\r\n }>(scenario.subjectKey.id, scenario.subjectCipherData);\r\n\r\n return {\r\n id: scenario.id,\r\n name,\r\n event,\r\n status: scenario.state,\r\n claimId: scenario.claim && scenario.claim.id,\r\n claimStatus: scenario.claim && scenario.claim.state,\r\n createdOn: scenario.created,\r\n lastModified: scenario.modified,\r\n };\r\n }\r\n\r\n public async getSharedScenario(scenarioId: string): Promise<SharedScenario> {\r\n const { sharedScenario } = await this.lrApollo.query<any>({\r\n query: GetSharedScenarioQuery,\r\n variables: {\r\n id: scenarioId,\r\n },\r\n });\r\n return await this.mapSharedScenario(sharedScenario);\r\n }\r\n\r\n private async mapSharedScenario(scenario: any): Promise<SharedScenario> {\r\n try {\r\n const claimantData = await this.getCipherData(scenario.asClaimant);\r\n const receiverData = await this.getCipherData(scenario.asReceiver);\r\n const approverData = await Promise.all<{\r\n event?: string;\r\n message?: string;\r\n }>(\r\n scenario.asApprovers.edges.map((x) =>\r\n this.getCipherData(x.node.approver)\r\n )\r\n );\r\n\r\n return {\r\n id: scenario.id,\r\n event:\r\n claimantData.event ||\r\n receiverData.event ||\r\n approverData.map((x) => x.event)[0],\r\n status: scenario.state,\r\n trustedParty: await this.tpService.mapTrustedParty(scenario.tp),\r\n isClaimant: !!scenario.asClaimant,\r\n claimantMessage: claimantData.message,\r\n isApprover: scenario.asApprovers.edges.length > 0,\r\n approverMessages: approverData.map((x) => x.message),\r\n isReceiver: !!scenario.asReceiver,\r\n receiverMessage: receiverData.message,\r\n receiverKeyId: scenario.asReceiver && scenario.asReceiver.sharedKey.id,\r\n receiverPbkId: scenario.asReceiver && scenario.asReceiver.pbk.id,\r\n receiverDirectories:\r\n scenario.asReceiver &&\r\n scenario.asReceiver.receiverDirectories.edges.map((x) => x.node),\r\n claim: scenario.sharedClaim\r\n ? {\r\n id: scenario.sharedClaim.id,\r\n isClaimant: scenario.sharedClaim.isClaimant,\r\n status: scenario.sharedClaim.state,\r\n asApprovers: await Promise.all<SharedScenarioClaimApprover>(\r\n scenario.sharedClaim.asClaimApprovers.edges\r\n .map((x) => x.node)\r\n .map(async (x) => ({\r\n approverId: x.approver.id,\r\n approverKey: await this.getApproverKey(x.approver),\r\n status: x.state,\r\n receivers: x.receivers.edges.map((y) => ({\r\n id: y.node.id,\r\n pbkId: y.node.pbk.id,\r\n })),\r\n }))\r\n ),\r\n asReceiver: scenario.sharedClaim.asClaimReceiver\r\n ? {\r\n received: scenario.sharedClaim.asClaimReceiver.received,\r\n ciphers: scenario.sharedClaim.asClaimReceiver.approvals.edges.map(\r\n (x) => x.node.receiverPbkCipher\r\n ),\r\n }\r\n : null,\r\n }\r\n : null,\r\n };\r\n } catch (e) {\r\n console.error('Failed to decrypt shared scenario.', e, scenario);\r\n return null;\r\n }\r\n }\r\n\r\n public async getTrustedPartyScenarios(\r\n trustedPartyId: string\r\n ): Promise<{\r\n myScenarios: ScenarioSummary[];\r\n sharedScenarios: SharedScenario[];\r\n }> {\r\n const { tp } = await this.lrApollo.query<any>({\r\n query: GetTrustedPartyScenariosQuery,\r\n variables: { partyId: trustedPartyId },\r\n });\r\n return {\r\n myScenarios: await Promise.all(\r\n tp.myScenarios.edges.map((x: any) => this.mapScenarioSummary(x.node))\r\n ),\r\n sharedScenarios: await Promise.all(\r\n tp.sharedScenarios.edges.map((x: any) => this.mapSharedScenario(x.node))\r\n ),\r\n };\r\n }\r\n\r\n public async getScenarioClaims(): Promise<ScenarioClaim[]> {\r\n const { scenarios } = await this.lrApollo.query<any>({\r\n query: GetAllScenarioClaimsQuery,\r\n });\r\n\r\n const claims = await Promise.all<ScenarioClaim[]>(\r\n scenarios.edges.map(async (x: any) => {\r\n const scenario = await this.mapScenarioSummary(x.node);\r\n\r\n return await Promise.all<ScenarioClaim>(\r\n x.node.claims.edges.map(async (y) => ({\r\n id: y.node.id,\r\n state: y.node.state,\r\n triggeredBy: await this.tpService.mapTrustedParty(\r\n y.node.claimant.tp\r\n ),\r\n triggeredOn: y.node.created,\r\n lastModified: y.node.modified,\r\n scenario,\r\n }))\r\n );\r\n })\r\n );\r\n\r\n return claims\r\n .reduce((x, y) => [...x, ...y], [])\r\n .sort(\r\n (x, y) =>\r\n -1 *\r\n moment(new Date(x.lastModified)).diff(\r\n moment(new Date(y.lastModified))\r\n )\r\n );\r\n }\r\n\r\n private async getCipherData(cipher?: {\r\n sharedKey: { id: string };\r\n sharedCipherData: string;\r\n }): Promise<{ event?: string; message?: string }> {\r\n if (!cipher) return {};\r\n\r\n return await this.keyGraph.decryptFromString<{\r\n event?: string;\r\n message?: string;\r\n }>(cipher.sharedKey.id, cipher.sharedCipherData);\r\n }\r\n\r\n private async getApproverKey(cipher?: {\r\n sharedKey: { id: string };\r\n sharedCipherPartialAssemblyKey: string;\r\n }): Promise<string> {\r\n if (!cipher) return null;\r\n\r\n return await this.keyGraph.decryptFromString<string>(\r\n cipher.sharedKey.id,\r\n cipher.sharedCipherPartialAssemblyKey\r\n );\r\n }\r\n\r\n public async getScenario(scenarioId: string): Promise<Scenario> {\r\n const { scenario } = await this.lrApollo.query<any>({\r\n query: GetScenarioQuery,\r\n variables: {\r\n id: scenarioId,\r\n categoryFilter: CategoryFilter,\r\n recordFilter: RecordFilter,\r\n contentFilter: RecordContentFilter,\r\n },\r\n });\r\n return await this.mapScenario(scenario);\r\n }\r\n\r\n private async mapScenario(scenario: any): Promise<Scenario> {\r\n const { name, event } = await this.keyGraph.decryptFromString<{\r\n event: string;\r\n name: string;\r\n }>(scenario.subjectKey.id, scenario.subjectCipherData);\r\n const claimants = await Promise.all<Claimant>(\r\n scenario.claimants.edges.map((x) =>\r\n this.scenarioClaimantService.mapClaimant(x.node)\r\n )\r\n );\r\n\r\n return {\r\n id: scenario.id,\r\n keyId: scenario.subjectKey.id,\r\n assemblyKeyId:\r\n scenario.approverAssembly && scenario.approverAssembly.assemblyKey.id,\r\n assemblyQuorum:\r\n scenario.approverAssembly && scenario.approverAssembly.quorum,\r\n name,\r\n event,\r\n status: scenario.state,\r\n claimants,\r\n approverGroups: scenario.approverAssembly\r\n ? await Promise.all(\r\n scenario.approverAssembly.subAssemblies.edges.map((x) =>\r\n this.scenarioApproverService.mapApproverGroup(x.node)\r\n )\r\n )\r\n : [],\r\n receivers: await Promise.all(\r\n scenario.receivers.edges.map((x) =>\r\n this.scenarioReceiverService.mapReceiver(x.node)\r\n )\r\n ),\r\n claim: scenario.claim\r\n ? {\r\n id: scenario.claim.id,\r\n status: scenario.claim.state,\r\n claimant: claimants.find(\r\n (x) => x.id === scenario.claim.claimant.id\r\n ),\r\n }\r\n : null,\r\n };\r\n }\r\n\r\n public async createScenario(input: CreateScenarioInput): Promise<string> {\r\n const rootKey = await this.keyService.getCurrentRootKey();\r\n\r\n const subjectKey = await this.keyFactory.createKey();\r\n const rootKeyWrappedSubjectKey = await this.keyGraph.encryptToString(\r\n rootKey.jwk,\r\n subjectKey.toJSON(true)\r\n );\r\n\r\n const subjectCipherData = await this.keyGraph.encryptToString(\r\n subjectKey,\r\n input.plainSubjectCipherData\r\n );\r\n\r\n const { createScenario } = await this.lrApollo.mutate<any>({\r\n mutation: CreateScenarioMutation,\r\n variables: {\r\n input: {\r\n rootKeyId: rootKey.id,\r\n rootKeyWrappedSubjectKey,\r\n subjectCipherData,\r\n },\r\n },\r\n });\r\n return createScenario.scenario.id;\r\n }\r\n\r\n public async updateScenario(input: UpdateScenarioInput): Promise<void> {\r\n await this.lrApollo.mutate<void>({\r\n mutation: UpdateScenarioMutation,\r\n variables: {\r\n input: {\r\n scenarioId: input.scenarioId,\r\n subjectKeyId: input.keyId,\r\n subjectCipherData: await this.keyGraph.encryptToString(\r\n input.keyId,\r\n input.plainSubjectCipherData\r\n ),\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async enableScenario(scenarioId: string): Promise<void> {\r\n await this.lrApollo.mutate<void>({\r\n mutation: EnableScenarioMutation,\r\n variables: { input: { scenarioId } },\r\n });\r\n }\r\n\r\n public async disableScenario(scenarioId: string): Promise<void> {\r\n await this.lrApollo.mutate<void>({\r\n mutation: DisableScenarioMutation,\r\n variables: { input: { scenarioId } },\r\n });\r\n }\r\n\r\n public async deleteScenario(scenarioId: string): Promise<void> {\r\n await this.lrApollo.mutate<void>({\r\n mutation: DeleteScenarioMutation,\r\n variables: { input: { scenarioId } },\r\n });\r\n }\r\n\r\n public async createClaim(scenarioId: string): Promise<string> {\r\n const res = await this.lrApollo.mutate<any>({\r\n mutation: CreateScenarioClaimMutation,\r\n variables: { input: { scenarioId } },\r\n });\r\n return res.createScenarioClaim.sharedClaim.id;\r\n }\r\n\r\n public async cancelClaim(claimId: string): Promise<void> {\r\n await this.lrApollo.mutate<void>({\r\n mutation: CancelScenarioClaimMutation,\r\n variables: { input: { claimId } },\r\n });\r\n }\r\n\r\n public async approveClaim(scenarioId: string, claimId: string) {\r\n return this.lrGraphQL.lrMutate(\r\n this.approveClaimMutation(scenarioId, claimId)\r\n );\r\n }\r\n\r\n public async approveClaimMutation(scenarioId: string, claimId: string) {\r\n const sharedScenario = await this.getSharedScenario(scenarioId);\r\n\r\n // Double check the claim matches\r\n if (sharedScenario.claim.id !== claimId) {\r\n throw new LrException({\r\n code: LrErrorCode.ReceiveClaimMismatch,\r\n message:\r\n 'claimId does not match with the current claimId of the scenario',\r\n });\r\n }\r\n\r\n const createMutation = async (asApprover: SharedScenarioClaimApprover) => {\r\n return new LrMutation({\r\n mutation: ApproveScenarioClaimMutation,\r\n variables: {\r\n input: {\r\n claimId,\r\n approverId: asApprover.approverId,\r\n receivers: await Promise.all(\r\n asApprover.receivers.map(async (y) => ({\r\n receiverId: y.id,\r\n receiverPbkCipher: await this.keyGraph.encryptToString(\r\n y.pbkId,\r\n { partialAssemblyKey: asApprover.approverKey }\r\n ),\r\n }))\r\n ),\r\n },\r\n },\r\n });\r\n };\r\n\r\n const mutations = sharedScenario.claim.asApprovers\r\n .filter((asApprover) => asApprover.status === ApproverClaimState.Claimed)\r\n .map((asApprover) => createMutation(asApprover));\r\n\r\n return LrMergedMutation.create(await Promise.all(mutations));\r\n }\r\n\r\n public async rejectClaim(scenarioId: string, claimId: string) {\r\n return this.lrGraphQL.lrMutate(\r\n this.rejectClaimMutation(scenarioId, claimId)\r\n );\r\n }\r\n\r\n public async rejectClaimMutation(scenarioId: string, claimId: string) {\r\n const sharedScenario = await this.getSharedScenario(scenarioId);\r\n\r\n // Double check the claim matches\r\n if (sharedScenario.claim.id !== claimId) {\r\n throw new LrException({\r\n code: LrErrorCode.ReceiveClaimMismatch,\r\n message:\r\n 'ClaimId does not match with the current claimId of the scenario',\r\n });\r\n }\r\n\r\n const createMutation = async (asApprover: SharedScenarioClaimApprover) => {\r\n return new LrMutation({\r\n mutation: RejectScenarioClaimMutation,\r\n variables: { input: { claimId, approverId: asApprover.approverId } },\r\n });\r\n };\r\n\r\n const mutations = sharedScenario.claim.asApprovers\r\n .filter((asApprover) => asApprover.status === ApproverClaimState.Claimed)\r\n .map((asApprover) => createMutation(asApprover));\r\n\r\n return LrMergedMutation.create(await Promise.all(mutations));\r\n }\r\n\r\n public async receiveClaim(\r\n scenarioId: string,\r\n claimId: string\r\n ): Promise<void> {\r\n // Get all the shared items\r\n const sharedScenario = await this.getSharedScenario(scenarioId);\r\n\r\n // Double check the claim matches\r\n if (sharedScenario.claim.id !== claimId) {\r\n throw new LrException({\r\n code: LrErrorCode.ReceiveClaimMismatch,\r\n message:\r\n 'ClaimId does not match with the current claimId of the scenario',\r\n });\r\n }\r\n if (sharedScenario.status !== ScenarioState.APPROVED) {\r\n throw new LrException({\r\n code: LrErrorCode.BadState,\r\n message: 'Scenario claim has not been approved',\r\n });\r\n }\r\n\r\n const assemblyKey = await this.getClaimAssemblyKey(\r\n sharedScenario.receiverPbkId,\r\n sharedScenario.claim.asReceiver.ciphers\r\n );\r\n\r\n // Decrypt all items\r\n const receiverDirectories = await Promise.all(\r\n sharedScenario.receiverDirectories.map(async (x) => {\r\n const wrappedItemKey = assemblyKey\r\n ? await this.encryptionService.decrypt(assemblyKey, x.wrappedItemKey)\r\n : x.wrappedItemKey;\r\n\r\n return {\r\n receiverDirectoryId: x.id,\r\n receiverSharedKeyWrappedItemKey: wrappedItemKey, // the wrappedItemKey is already wrapped by receiverSharedKey\r\n };\r\n })\r\n );\r\n\r\n await this.lrApollo.mutate<void>({\r\n mutation: ReceiveScenarioClaimMutation,\r\n variables: {\r\n input: {\r\n claimId,\r\n receiverDirectories,\r\n },\r\n },\r\n });\r\n }\r\n\r\n private async getClaimAssemblyKey(keyId: string, ciphers: string[]) {\r\n if (!ciphers || !ciphers.length) return null;\r\n\r\n let assemblyKeyParams: object;\r\n\r\n const shares = await Promise.all(\r\n ciphers.map(async (x) => {\r\n const { partialAssemblyKey } = await this.keyGraph.decryptFromString<{\r\n partialAssemblyKey: PartialAssemblyKey;\r\n }>(keyId, x);\r\n\r\n if (assemblyKeyParams) {\r\n if (\r\n JSON.stringify(assemblyKeyParams) !==\r\n JSON.stringify(partialAssemblyKey.assemblyKeyParams)\r\n ) {\r\n throw new LrException({\r\n code: LrErrorCode.BadState,\r\n message:\r\n 'The assembly key parameters are different between the approvals.',\r\n });\r\n }\r\n } else {\r\n assemblyKeyParams = partialAssemblyKey.assemblyKeyParams;\r\n }\r\n return partialAssemblyKey.slip39.share.mnemonics;\r\n })\r\n );\r\n\r\n const rawAssemblyKey = await this.slip39Service.recoverSecret(\r\n shares,\r\n ScenarioApproverService.SLIP39_PASSPHRASE\r\n );\r\n\r\n return await KFS.asKey({\r\n ...assemblyKeyParams,\r\n k: rawAssemblyKey,\r\n });\r\n }\r\n\r\n public async resetScenario(\r\n scenarioId: string,\r\n disable: boolean = false\r\n ): Promise<void> {\r\n const prepareReceiverItem = async (\r\n itemKeyId: string,\r\n sharedKeyId: string,\r\n assemblyKey: JWK.Key\r\n ): Promise<string> => {\r\n const sharedKey = await this.keyGraph.getKey(sharedKeyId);\r\n const itemKey = await this.keyGraph.getKey(itemKeyId);\r\n\r\n let wrappedItemKey = await this.keyGraph.encryptToString(\r\n sharedKey.jwk,\r\n itemKey.jwk.toJSON(true)\r\n );\r\n if (assemblyKey) {\r\n wrappedItemKey = await this.keyGraph.encryptToString(\r\n assemblyKey,\r\n wrappedItemKey\r\n );\r\n }\r\n return wrappedItemKey;\r\n };\r\n\r\n const prepareReceiverDirectories = async (\r\n receiver: Receiver,\r\n assemblyKey: JWK.Key\r\n ) => {\r\n return Promise.all([\r\n ...receiver.categories.map(async (receiverDirectory) => ({\r\n receiverDirectoryId: receiverDirectory.id,\r\n wrappedItemKey: await prepareReceiverItem(\r\n receiverDirectory.category.keyId,\r\n receiver.keyId,\r\n assemblyKey\r\n ),\r\n })),\r\n ...receiver.records.map(async (receiverDirectory) => ({\r\n receiverDirectoryId: receiverDirectory.id,\r\n wrappedItemKey: await prepareReceiverItem(\r\n receiverDirectory.record.keyId,\r\n receiver.keyId,\r\n assemblyKey\r\n ),\r\n })),\r\n ]);\r\n };\r\n\r\n const prepareReceivers = async (\r\n receivers: Receiver[],\r\n assemblyKey: JWK.Key\r\n ) => {\r\n return Promise.all(\r\n receivers.map(async (receiver) => ({\r\n receiverId: receiver.id,\r\n receiverDirectories: await prepareReceiverDirectories(\r\n receiver,\r\n assemblyKey\r\n ),\r\n receiverFiles: [],\r\n }))\r\n );\r\n };\r\n\r\n const prepareApprovers = async (approvers: Approver[]) => {\r\n return Promise.all(\r\n approvers.map(async (approver) => ({\r\n approverId: approver.id,\r\n sharedKeyId: approver.keyId,\r\n }))\r\n );\r\n };\r\n\r\n const prepareSubAssemblies = async (\r\n subAssemblies: ApprovalGroup[],\r\n assemblyKey: JWK.Key\r\n ) => {\r\n return Promise.all(\r\n subAssemblies.map(async (sa) => ({\r\n subAssemblyId: sa.id,\r\n subAssemblyCipherData: await this.keyGraph.encryptToString(\r\n assemblyKey,\r\n { name: sa.name }\r\n ),\r\n approvers: await prepareApprovers(sa.approvers),\r\n }))\r\n );\r\n };\r\n\r\n // ------------------------------------------------------------------------------\r\n // ------------------------------------------------------------------------------\r\n // ------------------------------------------------------------------------------\r\n\r\n const scenario = await this.getScenario(scenarioId);\r\n if (scenario.status !== ScenarioState.APPROVED) {\r\n throw new LrException({\r\n code: LrErrorCode.BadState,\r\n message: `Scenario must be in ${ScenarioState.APPROVED} state`,\r\n });\r\n }\r\n\r\n const subjectKey = await this.keyGraph.getKey(scenario.keyId);\r\n const newAssemblyKey = await this.keyFactory.createKey();\r\n\r\n const input: any = {\r\n scenarioId: scenario.id,\r\n disable,\r\n receivers: await prepareReceivers(scenario.receivers, newAssemblyKey),\r\n };\r\n\r\n // Approver assembly\r\n const subjectKeyWrappedAssemblyKey = await this.keyGraph.encryptToString(\r\n subjectKey.jwk,\r\n newAssemblyKey.toJSON(true)\r\n );\r\n\r\n input.approverAssembly = {\r\n subjectKeyId: subjectKey.id,\r\n subjectKeyWrappedAssemblyKey,\r\n assemblyCipherData: '',\r\n subAssemblies: await prepareSubAssemblies(\r\n scenario.approverGroups,\r\n newAssemblyKey\r\n ),\r\n };\r\n\r\n if (scenario.approverGroups.length) {\r\n const { k: rawAssemblyKey, ...assemblyKeyParams } = newAssemblyKey.toJSON(\r\n true\r\n ) as any;\r\n\r\n // Split the keys. If the scenario has been approved and there is an assembly setup, then\r\n // that assembly already enough members to meet quorum to approve the claim. So we can assume\r\n // that we can always do a key split here.\r\n const slipAssembly = new slip.Assembly(scenario.assemblyQuorum);\r\n\r\n scenario.approverGroups.forEach((sa, isa) => {\r\n let approverCount = sa.approvers.length;\r\n // if quorum is 1, then every approvers in the sub assembly shares the same partial key\r\n if (sa.quorum === 1) {\r\n approverCount = 1;\r\n }\r\n slipAssembly.addSubAssembly(\r\n new slip.SubAssembly(isa, sa.quorum, approverCount)\r\n );\r\n });\r\n\r\n await this.slip39Service.generateShares(\r\n rawAssemblyKey,\r\n ScenarioApproverService.SLIP39_PASSPHRASE,\r\n slipAssembly\r\n );\r\n\r\n // Copy the partial keys\r\n await Promise.all(\r\n scenario.approverGroups.map(async (sa, isa) => {\r\n const slipSubAssembly = slipAssembly.subAssemblies[isa];\r\n const inputSubAssembly = input.approverAssembly.subAssemblies[isa];\r\n\r\n await Promise.all(\r\n sa.approvers.map(async (approver, ia) => {\r\n const sharedKey = await this.keyGraph.getKey(approver.keyId);\r\n\r\n // if quorum is 1, then every approvers in the sub assembly shares the same partial key\r\n const share =\r\n sa.quorum === 1\r\n ? slipSubAssembly.shares[0]\r\n : slipSubAssembly.shares[ia];\r\n\r\n const partialAssemblyKey: PartialAssemblyKey = {\r\n slip39: {\r\n share,\r\n subAssembly: {\r\n quorum: sa.quorum,\r\n size: sa.approvers.length,\r\n },\r\n },\r\n assemblyKeyParams,\r\n };\r\n inputSubAssembly.approvers[\r\n ia\r\n ].sharedCipherPartialAssemblyKey = await this.keyGraph.encryptToString(\r\n sharedKey.jwk,\r\n partialAssemblyKey\r\n );\r\n })\r\n );\r\n })\r\n );\r\n }\r\n await this.lrApollo.mutate<any>({\r\n mutation: ResetScenarioMutation,\r\n variables: { input },\r\n });\r\n }\r\n\r\n public async getAllScenarioIds(): Promise<string[]> {\r\n const { scenarios } = await this.lrApollo.query<any>({\r\n query: GetAllScenarioIdsQuery,\r\n });\r\n return scenarios.edges.map((edge) => edge.node.id);\r\n }\r\n}\r\n","import { LrException } from './../_common/exceptions';\r\nimport { Injectable } from '@angular/core';\r\nimport { PreparedPermissions } from './../api/key-exchange.types';\r\nimport {\r\n CreateScenarioApprovalGroups,\r\n UpdateScenarioApprovalGroups,\r\n} from './approvals/scenario-approval.types';\r\nimport { ScenarioApproverService } from './approvals/scenario-approver.service';\r\nimport { ScenarioClaimantService } from './claimants/scenario-claimant.service';\r\nimport { ScenarioReceiverService } from './receivers/scenario-receiver.service';\r\nimport {\r\n Receiver,\r\n UpdateScenarioReceiverItemInput,\r\n} from './receivers/scenario-receiver.types';\r\nimport { ScenarioService } from './scenario.service';\r\nimport {\r\n NewScenario,\r\n UpdatedScenarioClaimant,\r\n UpdatedScenarioReceiver,\r\n UpdateScenario,\r\n} from './scenario.types';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class ScenarioSetupService {\r\n constructor(\r\n private scenarioService: ScenarioService,\r\n private scenarioClaimantService: ScenarioClaimantService,\r\n private scenarioApproverService: ScenarioApproverService,\r\n private scenarioReceiverService: ScenarioReceiverService\r\n ) {}\r\n\r\n public async setupScenario(\r\n newScenario: NewScenario\r\n ): Promise<{ scenarioId: string; error?: LrException }> {\r\n const scenarioId = await this.scenarioService.createScenario({\r\n plainSubjectCipherData: {\r\n event: newScenario.event,\r\n name: newScenario.name,\r\n },\r\n });\r\n\r\n try {\r\n await Promise.all(\r\n newScenario.claimants.map((x) =>\r\n this.updateClaimant(scenarioId, newScenario.event, x)\r\n )\r\n );\r\n\r\n const scenario = await this.scenarioService.getScenario(scenarioId);\r\n if (newScenario.approvalGroups.length) {\r\n const approvalGroups: CreateScenarioApprovalGroups = {\r\n scenarioId,\r\n keyId: scenario.keyId,\r\n event: scenario.event,\r\n singleReject: false,\r\n quorum: 1,\r\n plainAssemblyCipherData: null,\r\n\r\n approvalGroups: newScenario.approvalGroups.map((x) => ({\r\n quorum: x.quorum,\r\n singleReject: x.singleReject,\r\n plainSubAssemblyCipherData: { name: x.name },\r\n approvers: x.approvers.map((y) => ({\r\n trustedPartyId: y.trustedPartyId,\r\n trustedPartySharedKeyId: y.trustedPartySharedKeyId,\r\n plainSharedCipherData: {\r\n message: y.message,\r\n event: newScenario.event,\r\n },\r\n })),\r\n })),\r\n };\r\n scenario.assemblyKeyId = await this.scenarioApproverService.createScenarioApproverAssembly(\r\n approvalGroups\r\n );\r\n }\r\n await Promise.all(\r\n newScenario.receivers.map((x) =>\r\n this.updateReceiver(\r\n scenarioId,\r\n scenario.assemblyKeyId,\r\n newScenario.event,\r\n x\r\n )\r\n )\r\n );\r\n } catch (e) {\r\n return { scenarioId, error: e };\r\n }\r\n return { scenarioId };\r\n }\r\n\r\n public async updateScenario(updateScenario: UpdateScenario): Promise<void> {\r\n const params = {\r\n scenarioId: updateScenario.scenarioId,\r\n keyId: updateScenario.keyId,\r\n plainSubjectCipherData: {\r\n event: updateScenario.event,\r\n name: updateScenario.name,\r\n },\r\n };\r\n await this.scenarioService.updateScenario(params);\r\n\r\n await Promise.all(\r\n updateScenario.claimants.map((x) =>\r\n this.updateClaimant(updateScenario.scenarioId, updateScenario.event, x)\r\n )\r\n );\r\n await Promise.all(\r\n updateScenario.deletedClaimantIds.map((x) =>\r\n this.scenarioClaimantService.deleteClaimant(x)\r\n )\r\n );\r\n\r\n const assemblyKeyId = await this.updateApprovalGroups(updateScenario);\r\n\r\n await Promise.all(\r\n updateScenario.receivers.map((x) =>\r\n this.updateReceiver(\r\n updateScenario.scenarioId,\r\n assemblyKeyId,\r\n updateScenario.event,\r\n x\r\n )\r\n )\r\n );\r\n await Promise.all(\r\n updateScenario.deletedReceiverIds.map((x) =>\r\n this.scenarioReceiverService.deleteReceiver(x)\r\n )\r\n );\r\n }\r\n\r\n private async updateClaimant(\r\n scenarioId: string,\r\n event: string,\r\n claimant: UpdatedScenarioClaimant\r\n ) {\r\n if (claimant.claimantId) {\r\n await this.scenarioClaimantService.updateClaimant({\r\n id: claimant.claimantId,\r\n keyId: claimant.keyId,\r\n plainSharedCipherData: { message: claimant.message, event },\r\n });\r\n } else {\r\n await this.scenarioClaimantService.addClaimant({\r\n scenarioId,\r\n trustedPartyId: claimant.trustedPartyId,\r\n trustedPartySharedKeyId: claimant.trustedPartySharedKeyId,\r\n plainSharedCipherData: { message: claimant.message, event },\r\n });\r\n }\r\n }\r\n\r\n private async updateApprovalGroups(\r\n updateScenario: UpdateScenario\r\n ): Promise<string> {\r\n if (updateScenario.assemblyKeyId) {\r\n if (updateScenario.approvalGroups.length) {\r\n const approvalGroups: UpdateScenarioApprovalGroups = {\r\n scenarioId: updateScenario.scenarioId,\r\n assemblyKeyId: updateScenario.assemblyKeyId,\r\n\r\n singleReject: false,\r\n quorum: 1,\r\n\r\n approvalGroups: updateScenario.approvalGroups.map((x) => ({\r\n subAssemblyId: x.subAssemblyId,\r\n quorum: x.quorum,\r\n singleReject: x.singleReject,\r\n plainSubAssemblyCipherData: { name: x.name },\r\n approvers: x.approvers.map((y) => ({\r\n approverId: y.approverId,\r\n keyId: y.keyId,\r\n trustedPartyId: y.trustedPartyId,\r\n trustedPartySharedKeyId: y.trustedPartySharedKeyId,\r\n plainSharedCipherData: {\r\n message: y.message,\r\n event: updateScenario.event,\r\n },\r\n })),\r\n deletedApproverIds: x.deletedApproverIds,\r\n })),\r\n deletedGroupIds: updateScenario.deletedGroupIds,\r\n };\r\n await this.scenarioApproverService.updateScenarioApproverAssembly(\r\n approvalGroups\r\n );\r\n return updateScenario.assemblyKeyId;\r\n } else {\r\n const { receivers } = await this.scenarioService.getScenario(\r\n updateScenario.scenarioId\r\n );\r\n await this.scenarioApproverService.deleteScenarioApproverAssembly(\r\n updateScenario.scenarioId,\r\n updateScenario.event,\r\n receivers\r\n );\r\n return null;\r\n }\r\n // update or delete\r\n } else if (updateScenario.approvalGroups.length) {\r\n const { receivers } = await this.scenarioService.getScenario(\r\n updateScenario.scenarioId\r\n );\r\n\r\n const approvalGroups: CreateScenarioApprovalGroups = {\r\n scenarioId: updateScenario.scenarioId,\r\n keyId: updateScenario.keyId,\r\n event: updateScenario.event,\r\n singleReject: false,\r\n quorum: 1,\r\n approvalGroups: updateScenario.approvalGroups.map((x) => ({\r\n quorum: x.quorum,\r\n singleReject: x.singleReject,\r\n plainSubAssemblyCipherData: { name: x.name },\r\n approvers: x.approvers.map((y) => ({\r\n trustedPartyId: y.trustedPartyId,\r\n trustedPartySharedKeyId: y.trustedPartySharedKeyId,\r\n plainSharedCipherData: {\r\n message: y.message,\r\n event: updateScenario.event,\r\n },\r\n })),\r\n })),\r\n receivers,\r\n };\r\n return await this.scenarioApproverService.createScenarioApproverAssembly(\r\n approvalGroups\r\n );\r\n }\r\n return null;\r\n }\r\n\r\n private async updateReceiver(\r\n scenarioId: string,\r\n assemblyKeyId: string,\r\n event: string,\r\n receiver: UpdatedScenarioReceiver\r\n ) {\r\n let receiverId = receiver.receiverId;\r\n\r\n // Currently deleting all receivers below assembly logic.\r\n if (receiverId) {\r\n await this.scenarioReceiverService.updateReceiver({\r\n id: receiver.receiverId,\r\n keyId: receiver.keyId,\r\n plainSharedCipherData: { message: receiver.message, event },\r\n });\r\n } else {\r\n const newReceiver = {\r\n scenarioId,\r\n trustedPartyId: receiver.trustedPartyId,\r\n trustedPartySharedKeyId: receiver.trustedPartySharedKeyId,\r\n plainSharedCipherData: { message: receiver.message, event },\r\n };\r\n receiverId = await this.scenarioReceiverService.addReceiver(newReceiver);\r\n }\r\n const loadedReceiver = await this.scenarioReceiverService.getReceiver(\r\n receiverId\r\n );\r\n await this.updateReceiverItems(\r\n scenarioId,\r\n assemblyKeyId,\r\n loadedReceiver,\r\n receiver.permissions\r\n );\r\n }\r\n\r\n private async updateReceiverItems(\r\n scenarioId: string,\r\n assemblyKeyId: string,\r\n receiver: Receiver,\r\n permissions: PreparedPermissions\r\n ) {\r\n permissions = permissions || {};\r\n permissions.categories = permissions.categories || [];\r\n permissions.records = permissions.records || [];\r\n\r\n await Promise.all(\r\n permissions.categories\r\n .filter(\r\n (x) =>\r\n !receiver.categories.some((y) => y.category.id === x.categoryId)\r\n )\r\n .map(async (x) => {\r\n const params = {\r\n scenarioId,\r\n assemblyKeyId,\r\n receiverId: receiver.id,\r\n receiverKeyId: receiver.keyId,\r\n accessRole: x.accessLevel,\r\n categoryId: x.categoryId,\r\n };\r\n await this.scenarioReceiverService.addReceiverCategory(params);\r\n })\r\n );\r\n await Promise.all(\r\n permissions.records\r\n .filter(\r\n (x) => !receiver.records.some((y) => y.record.id === x.recordId)\r\n )\r\n .map(async (x) => {\r\n const params = {\r\n scenarioId,\r\n assemblyKeyId,\r\n receiverId: receiver.id,\r\n receiverKeyId: receiver.keyId,\r\n accessRole: x.accessLevel,\r\n recordId: x.recordId,\r\n };\r\n await this.scenarioReceiverService.addReceiverRecord(params);\r\n })\r\n );\r\n\r\n await Promise.all(\r\n permissions.categories\r\n .map((x) => ({\r\n accessLevel: x.accessLevel,\r\n category: receiver.categories.find(\r\n (y) => y.category.id === x.categoryId\r\n ),\r\n }))\r\n .filter((x) => x.category)\r\n .map(async (x) => {\r\n const params: UpdateScenarioReceiverItemInput = {\r\n id: x.category.id,\r\n keyId: x.category.keyId,\r\n accessRole: x.accessLevel,\r\n };\r\n await this.scenarioReceiverService.updateReceiverItem(params);\r\n })\r\n );\r\n await Promise.all(\r\n permissions.records\r\n .map((x) => ({\r\n accessLevel: x.accessLevel,\r\n record: receiver.records.find((y) => y.record.id === x.recordId),\r\n }))\r\n .filter((x) => x.record)\r\n .map(async (x) => {\r\n const params: UpdateScenarioReceiverItemInput = {\r\n id: x.record.id,\r\n keyId: x.record.keyId,\r\n accessRole: x.accessLevel,\r\n };\r\n await this.scenarioReceiverService.updateReceiverItem(params);\r\n })\r\n );\r\n\r\n await Promise.all(\r\n receiver.categories\r\n .filter(\r\n (x) =>\r\n !permissions.categories.some((y) => y.categoryId === x.category.id)\r\n )\r\n .map((x) => this.scenarioReceiverService.deleteReceiverItem(x.id))\r\n );\r\n await Promise.all(\r\n receiver.records\r\n .filter(\r\n (x) => !permissions.records.some((y) => y.recordId === x.record.id)\r\n )\r\n .map((x) => this.scenarioReceiverService.deleteReceiverItem(x.id))\r\n );\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport { SharedContactCardService } from '../api/shared-contact-card.service';\r\nimport { CurrentUser } from '../auth/auth.types';\r\nimport { LifeReadyAuthService } from '../auth/life-ready-auth.service';\r\nimport { TrustedPartyService } from '../trusted-parties/trusted-party.service';\r\nimport { SharedTrustedPartyDetails } from '../trusted-parties/trusted-party.types';\r\nimport { ProfileService } from './profile.service';\r\nimport {\r\n MainContactCardFields,\r\n MainContactCardProperty,\r\n TrustedPartyDetails,\r\n} from './profile.types';\r\nimport _ from 'lodash';\r\n\r\nenum ContactFields {\r\n Name = 'name',\r\n Email = 'email',\r\n Image = 'image',\r\n Phone = 'phone',\r\n Address = 'address',\r\n}\r\n\r\nconst FieldNames = [\r\n ContactFields.Name,\r\n ContactFields.Email,\r\n ContactFields.Image,\r\n ContactFields.Phone,\r\n ContactFields.Address,\r\n];\r\n\r\nclass FieldChange {\r\n field: string;\r\n id: string;\r\n label: string;\r\n oldValue?: any;\r\n newValue?: any;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class ProfileDetailsService {\r\n constructor(\r\n private sharedContactCardService: SharedContactCardService,\r\n private trustedPartyService: TrustedPartyService,\r\n private profileService: ProfileService,\r\n private authService: LifeReadyAuthService\r\n ) {}\r\n\r\n public async updateDetails(\r\n fields: MainContactCardFields\r\n ): Promise<CurrentUser> {\r\n const user = await this.authService.getUser();\r\n await this.profileService.updateDetails(\r\n user.contactCard.id,\r\n user.contactCard.keyId,\r\n fields\r\n );\r\n await this.synchronizeContactCards(fields, user.contactCard);\r\n return await this.authService.getUser(true);\r\n }\r\n\r\n private async synchronizeContactCards(\r\n newFields: MainContactCardFields,\r\n oldFields: MainContactCardFields\r\n ): Promise<void> {\r\n if (!oldFields) return;\r\n\r\n const changes = this.getChanges(newFields, oldFields);\r\n\r\n if (changes.length === 0) return;\r\n\r\n const trustedParties = await this.trustedPartyService.getTrustedParties();\r\n\r\n if (trustedParties.length === 0) return;\r\n\r\n for (const details of trustedParties.map((x) => x.mySharedDetails)) {\r\n await this.synchronizeSharedContactCard(details, changes);\r\n }\r\n }\r\n\r\n private getChanges(\r\n newFields: MainContactCardFields,\r\n oldFields: MainContactCardFields\r\n ): FieldChange[] {\r\n const changes: FieldChange[] = [];\r\n\r\n for (const field of FieldNames) {\r\n const oldField = oldFields[field];\r\n if (oldField && oldField.values) {\r\n for (const oldValue of oldField.values) {\r\n const newValue = (newFields[field].values as any[]).find(\r\n (x) => x.id === oldValue.id\r\n );\r\n\r\n if (!newValue) {\r\n changes.push({\r\n field,\r\n id: oldValue.id,\r\n label: oldValue.label,\r\n oldValue: oldValue.value,\r\n });\r\n } else if (!_.isEqual(newValue.value, oldValue.value)) {\r\n changes.push({\r\n field,\r\n id: oldValue.id,\r\n label: oldValue.label,\r\n oldValue: oldValue.value,\r\n newValue: newValue.value,\r\n });\r\n }\r\n }\r\n }\r\n }\r\n return changes;\r\n }\r\n\r\n private async synchronizeSharedContactCard(\r\n details: SharedTrustedPartyDetails,\r\n changes: FieldChange[]\r\n ): Promise<void> {\r\n let hasChanged = false;\r\n for (const change of changes) {\r\n switch (change.field) {\r\n case ContactFields.Phone:\r\n {\r\n const value =\r\n details.phones &&\r\n details.phones.find((x) => x.label === change.label);\r\n\r\n if (value) {\r\n hasChanged = true;\r\n value.value = change.newValue;\r\n }\r\n }\r\n break;\r\n case ContactFields.Address:\r\n {\r\n const value =\r\n details.addresses &&\r\n details.addresses.find((x) => x.label === change.label);\r\n\r\n if (value) {\r\n hasChanged = true;\r\n value.value = change.newValue;\r\n }\r\n }\r\n break;\r\n default: {\r\n const value = details[change.field];\r\n\r\n if (_.isEqual(value, change.oldValue)) {\r\n hasChanged = true;\r\n details[change.field] = change.newValue;\r\n }\r\n }\r\n }\r\n }\r\n if (hasChanged) {\r\n const { id, ownedKeyId, sharedKeyId, ...contactCard } = details;\r\n\r\n await this.sharedContactCardService.updateMySharedContactCard(\r\n id,\r\n ownedKeyId,\r\n sharedKeyId,\r\n contactCard\r\n );\r\n }\r\n }\r\n\r\n public async updateTrustedPartyDetails(details: SharedTrustedPartyDetails) {\r\n const { id, ownedKeyId, sharedKeyId, ...contactCard } = details;\r\n\r\n await this.sharedContactCardService.updateMySharedContactCard(\r\n id,\r\n ownedKeyId,\r\n sharedKeyId,\r\n contactCard\r\n );\r\n\r\n await this.synchronizeSharedDetails(details);\r\n }\r\n\r\n public async synchronizeSharedDetails(details: TrustedPartyDetails) {\r\n let { contactCard } = await this.authService.getUser();\r\n let hasNewValues = false;\r\n contactCard = { ...contactCard };\r\n\r\n if (details.name) {\r\n const property = this.checkField(details.name, contactCard.name);\r\n\r\n if (property) {\r\n contactCard.name = property;\r\n hasNewValues = true;\r\n }\r\n }\r\n\r\n if (details.email) {\r\n const property = this.checkField(details.email, contactCard.email);\r\n\r\n if (property) {\r\n contactCard.email = property;\r\n hasNewValues = true;\r\n }\r\n }\r\n\r\n if (details.image) {\r\n const property = this.checkField(details.image, contactCard.image);\r\n\r\n if (property) {\r\n contactCard.image = property;\r\n hasNewValues = true;\r\n }\r\n }\r\n\r\n if (details.phones && details.phones.length) {\r\n for (const phone of details.phones) {\r\n const property = this.checkField(\r\n phone.value,\r\n contactCard.phone,\r\n phone.label\r\n );\r\n\r\n if (property) {\r\n contactCard.phone = property;\r\n hasNewValues = true;\r\n }\r\n }\r\n }\r\n\r\n if (details.addresses && details.addresses.length) {\r\n for (const address of details.addresses) {\r\n const property = this.checkField(\r\n address.value,\r\n contactCard.address,\r\n address.label\r\n );\r\n\r\n if (property) {\r\n contactCard.address = property;\r\n hasNewValues = true;\r\n }\r\n }\r\n }\r\n\r\n if (hasNewValues) {\r\n await this.profileService.updateDetails(\r\n contactCard.id,\r\n contactCard.keyId,\r\n contactCard\r\n );\r\n }\r\n }\r\n\r\n private checkField<T>(\r\n field: T,\r\n property: MainContactCardProperty<T>,\r\n label: string = null\r\n ) {\r\n property = property || { value: field, hasMultiple: false };\r\n property.values = property.values || [];\r\n\r\n if (\r\n property.values.length === 0 ||\r\n property.values.every((x) => !_.isEqual(field, x.value))\r\n ) {\r\n property.values.push({\r\n id: `${label}-${new Date().getTime()}`,\r\n label,\r\n value: field,\r\n });\r\n property.hasMultiple = property.values.length > 1;\r\n property.value = property.value || field;\r\n return property;\r\n }\r\n return null;\r\n }\r\n}\r\n","import { Key } from '../cryptography/cryptography.types';\r\n\r\nexport interface GetUserInput {\r\n email?: string;\r\n username?: string;\r\n}\r\n\r\nexport interface User {\r\n id?: string;\r\n username?: string;\r\n haveTp: boolean;\r\n isCurrentUser: boolean;\r\n contactCards?: any;\r\n currentUserKey: {\r\n sigPxk?: Key;\r\n pxk?: Key;\r\n };\r\n}\r\n\r\nexport enum UserDeleteState {\r\n REQUESTED = 'REQUESTED',\r\n}\r\n\r\nexport interface UserDelete {\r\n created?: string;\r\n state: UserDeleteState;\r\n}\r\n","import { HttpClientModule } from '@angular/common/http';\r\nimport { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';\r\nimport Auth from '@aws-amplify/auth';\r\nimport { AuthClass } from '@aws-amplify/auth/lib-esm/Auth';\r\nimport { APOLLO_OPTIONS } from 'apollo-angular';\r\nimport { CookieService } from 'ngx-cookie-service';\r\nimport { FileService } from './api/file.service';\r\nimport { ProfileService } from './users/profile.service';\r\nimport { configureAmplifyAuth } from './auth/auth.config';\r\nimport {\r\n initialiseAuth,\r\n LifeReadyAuthService,\r\n} from './auth/life-ready-auth.service';\r\nimport { PasswordService } from './auth/password.service';\r\nimport { RegisterService } from './auth/register.service';\r\nimport { EncryptionService } from './cryptography/encryption.service';\r\nimport { KeyGraphService } from './cryptography/key-graph.service';\r\nimport { KeyService } from './cryptography/key.service';\r\nimport { KeyFactoryService } from './cryptography/key-factory.service';\r\nimport { WebCryptoService } from './cryptography/web-crypto.service';\r\nimport {\r\n configureApollo,\r\n LifeReadyConfig,\r\n LR_CONFIG,\r\n} from './life-ready.config';\r\nimport { TimeService } from './api/time.service';\r\nimport { NgIdleKeepaliveModule } from '@ng-idle/keepalive';\r\n\r\n@NgModule({\r\n imports: [HttpClientModule, NgIdleKeepaliveModule.forRoot()],\r\n providers: [\r\n CookieService,\r\n TimeService,\r\n FileService,\r\n ProfileService,\r\n RegisterService,\r\n LifeReadyAuthService,\r\n PasswordService,\r\n WebCryptoService,\r\n EncryptionService,\r\n KeyGraphService,\r\n KeyService,\r\n KeyFactoryService,\r\n ],\r\n})\r\nexport class LifeReadyModule {\r\n public static forRoot(\r\n config: LifeReadyConfig\r\n ): ModuleWithProviders<LifeReadyModule> {\r\n return {\r\n ngModule: LifeReadyModule,\r\n providers: [\r\n {\r\n provide: LR_CONFIG,\r\n useValue: config,\r\n },\r\n {\r\n provide: AuthClass,\r\n useValue: Auth,\r\n },\r\n {\r\n provide: APP_INITIALIZER,\r\n useFactory: configureAmplifyAuth,\r\n deps: [LR_CONFIG, AuthClass],\r\n multi: true,\r\n },\r\n {\r\n provide: APP_INITIALIZER,\r\n useFactory: initialiseAuth,\r\n deps: [LifeReadyAuthService],\r\n multi: true,\r\n },\r\n {\r\n provide: APOLLO_OPTIONS,\r\n useFactory: configureApollo,\r\n deps: [LR_CONFIG, AuthClass],\r\n },\r\n ],\r\n };\r\n }\r\n}\r\n","export class Plan {\r\n name: string;\r\n data: object;\r\n state: string;\r\n}\r\n\r\nexport class Subscription {\r\n id: string;\r\n}\r\n\r\nexport class UserPlan {\r\n id: string;\r\n plan: Plan;\r\n periodEnd: Date;\r\n subscription: Subscription;\r\n}\r\n\r\nexport class StripeCheckoutSession {\r\n id: string;\r\n}\r\n\r\nexport class StripeBillingPortalSession {\r\n url: string;\r\n}\r\n\r\nexport interface UserIssuablePlan {\r\n plan: Plan;\r\n}\r\n\r\nexport interface UserIssuedPlan {\r\n id: string;\r\n plan: Plan;\r\n token: string;\r\n tokenExpiryTime: Date;\r\n planPeriodEnd: Date;\r\n planPeriodEndAfterSeconds: number;\r\n}\r\n","import Fuse from 'fuse.js';\r\n\r\nexport enum SearchItemType {\r\n RECORD = 'RECORD',\r\n CATEGORY = 'CATEGORY',\r\n}\r\n\r\nexport interface SearchRecordAttachment {\r\n name: string;\r\n}\r\n\r\nexport interface SearchItem {\r\n id: string;\r\n type: SearchItemType;\r\n created: Date;\r\n modified: Date;\r\n archived: boolean;\r\n plainMeta: any;\r\n plainCipherMeta: any;\r\n parentCategoryId?: string;\r\n attachments?: SearchRecordAttachment[];\r\n}\r\n\r\nexport type SearchResults = Fuse.FuseResult<SearchItem>[];\r\n","import gql from 'graphql-tag';\r\nimport { KeyGraphFragment } from '../_common/queries.gql';\r\nconst MAX_CATEGORY_DEPTH = 4;\r\nconst DEFAULT_CATEGORY_DEPTH = 4;\r\n\r\nexport const SearchRecordContentsQuery = gql`\r\n query GetRecordContents(\r\n $id: LrRelayIdInput!\r\n $depth: Int\r\n $first: Int\r\n $after: String\r\n $recordContentFilter: LrJSONFilter!\r\n ) {\r\n category: directory(id: $id) {\r\n descendantDirectories(depth: $depth) {\r\n recordContents: files(\r\n first: $first\r\n after: $after\r\n plainMeta: $recordContentFilter\r\n orderBy: \"-created\"\r\n ) {\r\n edges {\r\n node {\r\n currentVersion {\r\n state {\r\n keyId\r\n plainMeta\r\n cipherMeta\r\n contentResource\r\n }\r\n }\r\n nParentDirectoryLinks(n: 1) {\r\n list {\r\n parentDirectory {\r\n id\r\n keyId\r\n created\r\n modified\r\n archived\r\n plainMeta\r\n cipherMeta\r\n nParentDirectoryLinks(n: 3) {\r\n list {\r\n parentDirectory {\r\n id\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n keyGraph {\r\n ...KeyGraphFragment\r\n }\r\n }\r\n ${KeyGraphFragment}\r\n`;\r\n","import { Injectable, NgZone } from '@angular/core';\r\nimport { LrApolloService } from '../api/lr-apollo.service';\r\nimport { CategoryService } from '../category/category.service';\r\nimport { KeyFactoryService } from '../cryptography/key-factory.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { RecordFieldType } from '../record-type/record-type.types';\r\nimport { RecordContentFilter } from '../record/record.gql';\r\nimport { RecordService } from '../record/record.service';\r\nimport { RunOutsideAngular } from '../_common/run-outside-angular';\r\nimport { SearchRecordContentsQuery } from './search.gql';\r\nimport { SearchItem, SearchItemType } from './search.types';\r\n\r\nasync function debugPopulateCategory(\r\n categoryService: CategoryService,\r\n recordService: RecordService,\r\n keyFactory: KeyFactoryService,\r\n categoryId: string,\r\n recordsPerCategory: number\r\n) {\r\n const tasks = [];\r\n\r\n const category = await categoryService.getCategory(categoryId);\r\n\r\n // Create records\r\n for (let i = category.records.length; i < recordsPerCategory; ++i) {\r\n const name = `${category.category.name}+${keyFactory.randomString(16)}`;\r\n console.log('Creating record: ', name);\r\n await recordService.createRecord({\r\n categoryIds: [category.category.id],\r\n name,\r\n recordType: {\r\n id: '1',\r\n version: 1,\r\n name: 'Vehicle Details',\r\n },\r\n fields: [\r\n {\r\n id: '1-vin',\r\n type: RecordFieldType.Text,\r\n label: 'VIN Number',\r\n value: '1234567890',\r\n },\r\n {\r\n id: '1-location',\r\n type: RecordFieldType.Text,\r\n label: 'Location',\r\n value: '10'.repeat(1000),\r\n },\r\n ],\r\n // attachments\r\n });\r\n }\r\n\r\n // Delete records\r\n for (let i = category.records.length; i > recordsPerCategory; --i) {\r\n const id = category.records[i - 1].id;\r\n console.log('Deleting record: ', id);\r\n await recordService.deleteRecord(id);\r\n }\r\n}\r\n\r\nexport async function debugPopulateRecords(\r\n categoryService: CategoryService,\r\n recordService: RecordService,\r\n keyFactory: KeyFactoryService,\r\n recordsPerCategory: number\r\n) {\r\n const pillars = await categoryService.getCategories();\r\n\r\n // For each category, added records\r\n for (const pillar of pillars) {\r\n const category = await categoryService.getCategory(pillar.id);\r\n for (const subCategory of category.subCategories) {\r\n if (subCategory.allowRecords) {\r\n await debugPopulateCategory(\r\n categoryService,\r\n recordService,\r\n keyFactory,\r\n subCategory.id,\r\n recordsPerCategory\r\n );\r\n }\r\n }\r\n }\r\n}\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class SearchService {\r\n vaultItems: { [itemId: string]: SearchItem } = {};\r\n recordContentsResult: any;\r\n\r\n constructor(\r\n private ngZone: NgZone,\r\n private lrApollo: LrApolloService,\r\n private categoryService: CategoryService,\r\n private keyGraph: KeyGraphService\r\n ) {}\r\n\r\n private async mapRecordContent(recordContent: any): Promise<SearchItem> {\r\n const record = recordContent.nParentDirectoryLinks.list[0].parentDirectory;\r\n const state = recordContent.currentVersion.state;\r\n\r\n const plainCipherMeta =\r\n state.cipherMeta &&\r\n (await this.keyGraph.decryptFromString<any>(\r\n state.keyId,\r\n state.cipherMeta\r\n ));\r\n\r\n return {\r\n type: SearchItemType.RECORD,\r\n id: record.id,\r\n created: new Date(record.created),\r\n modified: new Date(record.modified),\r\n archived: record.archived,\r\n plainMeta:\r\n state.plainMeta &&\r\n JSON.parse(recordContent.currentVersion.state.plainMeta),\r\n plainCipherMeta,\r\n parentCategoryId: record.nParentDirectoryLinks.list[0].parentDirectory.id,\r\n };\r\n }\r\n\r\n private async mapRecordContents(edges: any[]): Promise<SearchItem[]> {\r\n return Promise.all(edges.map((edge) => this.mapRecordContent(edge.node)));\r\n }\r\n\r\n private async load() {\r\n const defaultVault = await this.categoryService.getDefaultVault();\r\n let start;\r\n let end;\r\n\r\n start = Date.now();\r\n\r\n this.recordContentsResult = await this.lrApollo.query<any>({\r\n query: SearchRecordContentsQuery,\r\n variables: {\r\n id: defaultVault.id,\r\n depth: 5,\r\n first: null,\r\n after: null,\r\n recordContentFilter: RecordContentFilter,\r\n },\r\n });\r\n\r\n end = Date.now();\r\n console.log('Search API time (s): ', (end - start) / 1000);\r\n\r\n start = Date.now();\r\n // try {\r\n const items = await this.mapRecordContents(\r\n this.recordContentsResult.category.descendantDirectories.recordContents\r\n .edges\r\n );\r\n for (const item of items) {\r\n this.vaultItems[item.id] = item;\r\n }\r\n\r\n end = Date.now();\r\n console.log('Search mapCategory time (s): ', (end - start) / 1000);\r\n }\r\n\r\n public async refresh() {\r\n await this.load();\r\n\r\n console.log(Object.values(this.vaultItems));\r\n return this.vaultItems;\r\n }\r\n}\r\n","import { Connection, ContactCardNode, ID } from './types';\r\nimport { gqlTyped } from '../_common/ast';\r\n\r\nexport const ContactCardFragment = gqlTyped<ContactCardNode>`\r\n fragment ContactCardFragment on ContactCardNode {\r\n id\r\n publicData\r\n publicSearchable\r\n cipherData\r\n key {\r\n id\r\n }\r\n }\r\n`;\r\n\r\nexport interface CreateContactCardMutation {\r\n createContactCard: {\r\n contactCard: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const CreateContactCardMutation = gqlTyped<CreateContactCardMutation>`\r\n mutation CreateContactCardMutation(\r\n $input: CreateContactCardInput!\r\n ) {\r\n createContactCard(input: $input) {\r\n contactCard {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport interface UpdateContactCardMutation {\r\n updateContactCard: {\r\n contactCard: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const UpdateContactCardMutation = gqlTyped<UpdateContactCardMutation>`\r\n mutation UpdateContactCardMutation($input: UpdateContactCardInput!) {\r\n updateContactCard(input: $input) {\r\n contactCard {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport interface DeleteContactCardMutation {\r\n deleteContactCard: {\r\n deleteContactCard: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const DeleteContactCardMutation = gqlTyped<DeleteContactCardMutation>`\r\n mutation DeleteContactCardMutation($input: DeleteContactCardInput!) {\r\n deleteContactCard(input: $input) {\r\n id\r\n }\r\n }\r\n`;\r\n\r\nexport interface ContactCardsQuery {\r\n contactCards: Connection<ContactCardNode>;\r\n}\r\nexport const ContactCardsQuery = gqlTyped<ContactCardsQuery>`\r\n query ContactCardsQuery {\r\n contactCards(orderBy: \"created\") {\r\n edges {\r\n node {\r\n ...ContactCardFragment\r\n }\r\n }\r\n }\r\n }\r\n ${ContactCardFragment}\r\n`;\r\n\r\nexport interface ContactCardQuery {\r\n contactCard: ContactCardNode;\r\n}\r\nexport const ContactCardQuery = gqlTyped<ContactCardQuery>`\r\n query ContactCardQuery($id: LrRelayIdInput!) {\r\n contactCard(id: $id) {\r\n ...ContactCardFragment\r\n }\r\n }\r\n ${ContactCardFragment}\r\n`;\r\n","import { Injectable, NgZone } from '@angular/core';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { KeyFactoryService } from '../cryptography/key-factory.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { KeyMetaService } from '../cryptography/key-meta.service';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport { MainContactCardPlainFields } from '../users/profile.types';\r\nimport { RunOutsideAngular } from '../_common/run-outside-angular';\r\nimport {\r\n CreateContactCardMutation,\r\n DeleteContactCardMutation,\r\n UpdateContactCardMutation,\r\n} from './contact-card2.gql';\r\nimport { LrMutation } from './lr-graphql';\r\n\r\nexport interface CreateContactCardInput2 {\r\n publicDataJson: any;\r\n publicSearchableJson: any;\r\n plainCipherDataJson: any;\r\n plainDataJson: MainContactCardPlainFields;\r\n}\r\n\r\n// These contact name fields are enforced by the server so that it can send out emails with\r\n// appropriate format.\r\nexport interface ContactCardName2 {\r\n name: string;\r\n title?: string;\r\n firstName?: string;\r\n lastName?: string;\r\n // additional fields are not allowed by the server\r\n}\r\n\r\nexport class OwnerPlainDataJson {\r\n name: ContactCardName2;\r\n}\r\n\r\nexport interface UpdateContactCardInput2 extends CreateContactCardInput2 {\r\n id: string;\r\n keyId: string;\r\n}\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class ContactCard2Service {\r\n constructor(\r\n private keyFactory: KeyFactoryService,\r\n private keyService: KeyService,\r\n private encryptionService: EncryptionService,\r\n private keyGraph: KeyGraphService,\r\n private keyMetaService: KeyMetaService,\r\n private ngZone: NgZone\r\n ) {}\r\n\r\n async createContactCard(input: CreateContactCardInput2) {\r\n // Get encryption key\r\n const rootKey = await this.keyService.getCurrentRootKey();\r\n const key = await this.keyFactory.createKey();\r\n const wrappedKey = await this.keyGraph.encryptToString(\r\n rootKey.jwk,\r\n key.toJSON(true)\r\n );\r\n const cipherData = await this.keyGraph.encryptToString(\r\n key,\r\n input.plainCipherDataJson\r\n );\r\n\r\n const params = await this.prepareContactCardInput(input);\r\n\r\n return new LrMutation({\r\n mutation: CreateContactCardMutation,\r\n variables: {\r\n input: {\r\n ...params,\r\n wrappingKeyId: rootKey.id,\r\n wrappedKey,\r\n cipherData,\r\n },\r\n },\r\n });\r\n }\r\n\r\n async updateContactCard(input: UpdateContactCardInput2) {\r\n // Get encryption key\r\n const cipherData = await this.keyGraph.encryptToString(\r\n input.keyId,\r\n input.plainCipherDataJson\r\n );\r\n\r\n const params = await this.prepareContactCardInput(input);\r\n\r\n return new LrMutation({\r\n mutation: UpdateContactCardMutation,\r\n variables: {\r\n input: {\r\n ...params,\r\n id: input.id,\r\n cipherData,\r\n },\r\n },\r\n });\r\n }\r\n\r\n deleteContactCard(id: string) {\r\n return new LrMutation({\r\n mutation: DeleteContactCardMutation,\r\n variables: {\r\n input: {\r\n id,\r\n },\r\n },\r\n });\r\n }\r\n\r\n private async prepareContactCardInput(\r\n input: CreateContactCardInput2\r\n ): Promise<any> {\r\n const sigPxk = await this.keyService.getCurrentSigPxk();\r\n const publicDataSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, input.publicDataJson)\r\n );\r\n const publicSearchableSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, input.publicSearchableJson)\r\n );\r\n const plainDataSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, input.plainDataJson)\r\n );\r\n\r\n return {\r\n sigPxkId: sigPxk.id,\r\n publicDataSig,\r\n publicSearchableSig,\r\n plainDataSig,\r\n };\r\n }\r\n}\r\n","import { gqlTyped } from '../_common/ast';\r\nimport { DateTime, ID } from './types';\r\n\r\n// --------------------------------------------------------------------\r\n// Queries\r\n// --------------------------------------------------------------------\r\nexport interface DirectoryKeyQuery {\r\n directory: {\r\n keyId: ID;\r\n };\r\n}\r\nexport const DirectoryKeyQuery = gqlTyped<DirectoryKeyQuery>`\r\nquery DirectoryKeyQuery($id: LrRelayIdInput!) {\r\n directory(id: $id) {\r\n keyId\r\n }\r\n}\r\n`;\r\n\r\nexport interface FileKeyQuery {\r\n file: {\r\n keyId: ID;\r\n };\r\n}\r\nexport const FileKeyQuery = gqlTyped<FileKeyQuery>`\r\nquery FileKeyQuery($id: LrRelayIdInput!) {\r\n file(id: $id) {\r\n keyId\r\n }\r\n}\r\n`;\r\n\r\nexport interface FileStateKeyQuery {\r\n fileState: {\r\n keyId: ID;\r\n };\r\n}\r\nexport const FileStateKeyQuery = gqlTyped<FileStateKeyQuery>`\r\nquery FileStateKeyQuery($id: LrRelayIdInput!) {\r\n fileState(id: $id) {\r\n keyId\r\n }\r\n}\r\n`;\r\n\r\n// --------------------------------------------------------------------\r\n// Mutations\r\n// --------------------------------------------------------------------\r\nexport interface CreateDirectoryMutation {\r\n createDirectory: {\r\n directory: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const CreateDirectoryMutation = gqlTyped<CreateDirectoryMutation>`\r\nmutation CreateDirectoryMutation($input: CreateDirectoryInput!) {\r\n createDirectory(input: $input) {\r\n directory {\r\n id\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport interface UpdateDirectoryMutation {\r\n updateDirectory: {\r\n directory: {\r\n id: ID;\r\n modified: DateTime;\r\n };\r\n };\r\n}\r\nexport const UpdateDirectoryMutation = gqlTyped<UpdateDirectoryMutation>`\r\nmutation UpdateDirectoryMutation($input: UpdateDirectoryInput!) {\r\n updateDirectory(input: $input) {\r\n directory {\r\n id\r\n modified\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport interface DeleteDirectoryMutation {\r\n deleteDirectory: {\r\n id: ID;\r\n };\r\n}\r\nexport const DeleteDirectoryMutation = gqlTyped<DeleteDirectoryMutation>`\r\nmutation DeleteDirectoryMutation($input: DeleteDirectoryInput!) {\r\n deleteDirectory(input: $input) {\r\n id\r\n }\r\n}\r\n`;\r\n\r\nexport interface CreateFileMutation {\r\n createFile: {\r\n file: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const CreateFileMutation = gqlTyped<CreateFileMutation>`\r\nmutation CreateFileMutation($input: CreateFileInput!) {\r\n createFile(input: $input) {\r\n file {\r\n id\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport interface UpdateFileMutation {\r\n updateFile: {\r\n file: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const UpdateFileMutation = gqlTyped<UpdateFileMutation>`\r\nmutation UpdateFileMutation($input: UpdateFileInput!) {\r\n updateFile(input: $input) {\r\n file {\r\n id\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport interface DeleteFileMutation {\r\n deleteFile: {\r\n id: ID;\r\n };\r\n}\r\nexport const DeleteFileMutation = gqlTyped<DeleteFileMutation>`\r\nmutation DeleteFileMutation($input: DeleteFileInput!) {\r\n deleteFile(input: $input) {\r\n id\r\n }\r\n}\r\n`;\r\n\r\nexport interface ArchiveDirectoryMutation {\r\n archiveDirectory: {\r\n directory: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const ArchiveDirectoryMutation = gqlTyped<ArchiveDirectoryMutation>`\r\nmutation ArchiveDirectoryMutation($input: ArchiveDirectoryInput!) {\r\n archiveDirectory(input: $input) {\r\n directory {\r\n id\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport interface UnarchiveDirectoryMutation {\r\n unarchiveDirectory: {\r\n directory: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const UnarchiveDirectoryMutation = gqlTyped<UnarchiveDirectoryMutation>`\r\nmutation UnarchiveDirectoryMutation($input: UnarchiveDirectoryInput!) {\r\n unarchiveDirectory(input: $input) {\r\n directory {\r\n id\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport interface ChangeDirectoryParentsMutationResult {\r\n unarchiveDirectory: {\r\n directory: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const ChangeDirectoryParentsMutation = gqlTyped<ChangeDirectoryParentsMutationResult>`\r\nmutation ChangeDirectoryParentsMutation($input: ChangeDirectoryParentsInput!) {\r\n changeDirectoryParents(input: $input) {\r\n directory {\r\n id\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport interface ChangeFileParentsMutationResult {\r\n unarchiveDirectory: {\r\n directory: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const ChangeFileParentsMutation = gqlTyped<ChangeFileParentsMutationResult>`\r\nmutation ChangeFileParentsMutation($input: ChangeFileParentsInput!) {\r\n changeFileParents(input: $input) {\r\n file {\r\n id\r\n }\r\n }\r\n}\r\n`;\r\n","import { Injectable, Injector, NgZone } from '@angular/core';\r\nimport { JWK } from 'node-jose';\r\nimport { KeyFactoryService } from '../cryptography/key-factory.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { KeyMetaService } from '../cryptography/key-meta.service';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport { LrBadArgumentException } from '../_common/exceptions';\r\nimport { RunOutsideAngular } from '../_common/run-outside-angular';\r\nimport { FileService } from './file.service';\r\nimport { LrGraphQLService, LrMutation, LrService } from './lr-graphql';\r\nimport {\r\n DirectoryKeyQuery,\r\n CreateDirectoryMutation,\r\n DeleteDirectoryMutation,\r\n CreateFileMutation,\r\n DeleteFileMutation,\r\n FileKeyQuery,\r\n FileStateKeyQuery,\r\n UpdateFileMutation,\r\n UpdateDirectoryMutation,\r\n ArchiveDirectoryMutation,\r\n UnarchiveDirectoryMutation,\r\n ChangeDirectoryParentsMutation,\r\n ChangeFileParentsMutation,\r\n} from './item2.gql';\r\nimport { ID, LrRelayIdInput } from './types';\r\n\r\nexport enum DirectoryLinkType {\r\n HARD = 'HARD',\r\n}\r\n\r\n// Suffix \"Options\" are what's need by the KC client.\r\nexport interface ParentDirectoryOptions {\r\n directoryId: LrRelayIdInput;\r\n // If wrapping key provided, then we can try fetching it from the\r\n // key graph. If not found in key graph, then fetch the directory.\r\n wrappingKeyId?: LrRelayIdInput;\r\n // TODO: this can be other types, but server side implementation has not been\r\n // thoroughly tested. So best not use anything else and just leave it out so\r\n // server uses the default value of \"HARD\"\r\n linkType?: DirectoryLinkType.HARD;\r\n}\r\n\r\nexport interface ParentRootDirectoryInput {\r\n wrappedKey: string;\r\n wrappingKeyId: LrRelayIdInput;\r\n}\r\n\r\n// Suffix \"Input\" matched with the graphql types\r\n// TODO these should be change to be exactly the same on the server since all that differs\r\n// is the wrappedKey/wrappedFileKey name\r\nexport interface ParentDirectoryInputBase {\r\n directoryId: LrRelayIdInput;\r\n wrappingKeyId: LrRelayIdInput;\r\n linkType?: DirectoryLinkType.HARD;\r\n}\r\n\r\nexport interface ParentDirectoryInput extends ParentDirectoryInputBase {\r\n wrappedKey: string;\r\n}\r\n\r\nexport interface FileParentDirectoryInput extends ParentDirectoryInputBase {\r\n wrappedFileKey: string;\r\n}\r\n\r\nexport interface DownloadFileContentOptions {\r\n fileStateNodeId: LrRelayIdInput;\r\n fileStateKeyId?: LrRelayIdInput;\r\n}\r\n\r\nexport interface CommonDirectoryOptions {\r\n plainMetaJson?: any;\r\n cipherMetaClearJson?: any;\r\n}\r\n\r\nexport interface CreateDirectoryOptions extends CommonDirectoryOptions {\r\n asRootDirectory?: boolean;\r\n parentDirectories?: ParentDirectoryOptions[];\r\n}\r\n\r\nexport interface UpdateDirectoryOptions extends CommonDirectoryOptions {\r\n directoryId: LrRelayIdInput;\r\n directoryKeyId?: LrRelayIdInput;\r\n}\r\n\r\nexport interface CommonFileOptions {\r\n plainMetaJson?: any;\r\n cipherMetaClearJson?: any;\r\n file?: File;\r\n // custom uploader\r\n upload?: (cipherFileContent: string) => Promise<string>;\r\n}\r\n\r\nexport interface CreateFileOptions extends CommonFileOptions {\r\n parentDirectories: ParentDirectoryOptions[];\r\n}\r\n\r\nexport interface UpdateFileOptions extends CommonFileOptions {\r\n fileId: LrRelayIdInput;\r\n fileKeyId?: LrRelayIdInput;\r\n}\r\n\r\ninterface ChangeItemParentsOptions {\r\n parentsToRemove: LrRelayIdInput[];\r\n parentsToAdd: ParentDirectoryOptions[];\r\n}\r\n\r\nexport interface ChangeDirectoryParentsOptions\r\n extends ChangeItemParentsOptions {\r\n directoryId: LrRelayIdInput;\r\n directoryKeyId?: LrRelayIdInput;\r\n}\r\n\r\nexport interface ChangeFileParentsOptions extends ChangeItemParentsOptions {\r\n fileId: LrRelayIdInput;\r\n fileKeyId?: LrRelayIdInput;\r\n}\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class Item2Service extends LrService {\r\n constructor(\r\n private ngZone: NgZone,\r\n private injector: Injector,\r\n private fileService: FileService,\r\n private keyService: KeyService,\r\n private keyMeta: KeyMetaService,\r\n private keyFactory: KeyFactoryService,\r\n private keyGraph: KeyGraphService\r\n ) {\r\n super(injector);\r\n }\r\n\r\n public async downloadFileContent(\r\n options: DownloadFileContentOptions\r\n ): Promise<ArrayBuffer> {\r\n const fileContent = await this.fileService.downloadEncryptedFile2(\r\n options.fileStateNodeId\r\n );\r\n\r\n const fileStateKey = await this.keyGraph.getKey(\r\n options.fileStateKeyId,\r\n () => this.getFileStateKeyId(options.fileStateNodeId)\r\n );\r\n\r\n return this.keyGraph.decryptFromString(fileStateKey, fileContent, {\r\n payloadType: 'ArrayBuffer',\r\n });\r\n }\r\n\r\n public async createDirectory(options: CreateDirectoryOptions) {\r\n const directoryKey = await this.keyFactory.createKey();\r\n options.parentDirectories = options.parentDirectories || [];\r\n if (!options.asRootDirectory && !options.parentDirectories?.length) {\r\n throw new LrBadArgumentException(\r\n 'A new directory must be either a root directory or a sub-directory. So you must provide either parentDirectories and/or asRootDirectory parameter.'\r\n );\r\n }\r\n\r\n const parentDirectories = await Promise.all(\r\n options.parentDirectories?.map((t) =>\r\n this.getParentDirectoryInput(t, directoryKey)\r\n )\r\n );\r\n\r\n // TODO this is rather an unfortunate name, change it to asRootDirectory.\r\n let parentRootDirectory: ParentRootDirectoryInput;\r\n if (options.asRootDirectory) {\r\n const rootKey = this.keyService.getCurrentRootKey();\r\n parentRootDirectory = {\r\n wrappingKeyId: rootKey.id,\r\n wrappedKey: await this.keyGraph.wrapKey(rootKey, directoryKey),\r\n };\r\n }\r\n\r\n const input = {\r\n ...(await this.getInput(directoryKey, options)),\r\n parentDirectories,\r\n parentRootDirectory,\r\n };\r\n\r\n return new LrMutation({\r\n mutation: CreateDirectoryMutation,\r\n variables: {\r\n input,\r\n },\r\n });\r\n }\r\n\r\n updateDirectoryExec(options: UpdateDirectoryOptions) {\r\n return this.mutate(this.updateDirectoryMutation(options));\r\n }\r\n\r\n updateDirectory(options: UpdateDirectoryOptions) {\r\n return this.updateDirectoryMutation(options);\r\n }\r\n\r\n async updateDirectoryMutation(options: UpdateDirectoryOptions) {\r\n const directoryKey = await this.getDirectoryKey(\r\n options.directoryId,\r\n options.directoryKeyId\r\n );\r\n\r\n return new LrMutation({\r\n mutation: UpdateDirectoryMutation,\r\n variables: {\r\n input: {\r\n ...(await this.getInput(directoryKey.jwk, options)),\r\n directoryId: options.directoryId,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public deleteDirectory(id: ID) {\r\n return new LrMutation({\r\n mutation: DeleteDirectoryMutation,\r\n variables: {\r\n input: {\r\n directoryId: id,\r\n },\r\n },\r\n });\r\n }\r\n\r\n async createFile(options: CreateFileOptions) {\r\n const fileKey = await this.keyFactory.createKey();\r\n\r\n const parentDirectories = await Promise.all(\r\n options.parentDirectories.map(async (t) => {\r\n const {\r\n directoryId,\r\n wrappingKeyId,\r\n wrappedKey,\r\n } = await this.getParentDirectoryInput(t, fileKey);\r\n // remap from ParentDirectoryInput to FileParentDirectoryInput\r\n // TODO the server should really just use wrappedKey instead of wrappedFileKey\r\n return {\r\n directoryId,\r\n wrappingKeyId,\r\n wrappedFileKey: wrappedKey,\r\n } as FileParentDirectoryInput;\r\n })\r\n );\r\n\r\n return new LrMutation({\r\n mutation: CreateFileMutation,\r\n variables: {\r\n input: {\r\n ...(await this.createFileState(fileKey, options)),\r\n parentDirectories,\r\n },\r\n },\r\n });\r\n }\r\n\r\n async updateFile(options: UpdateFileOptions) {\r\n const fileKey = await this.getFileKey(options.fileId, options.fileKeyId);\r\n\r\n return new LrMutation({\r\n mutation: UpdateFileMutation,\r\n variables: {\r\n input: {\r\n ...(await this.createFileState(fileKey.jwk, options)),\r\n fileId: options.fileId,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public deleteFile(id: ID) {\r\n return new LrMutation({\r\n mutation: DeleteFileMutation,\r\n variables: {\r\n input: {\r\n fileId: id,\r\n },\r\n },\r\n });\r\n }\r\n\r\n private async getParentDirectoryInput(\r\n options: ParentDirectoryOptions,\r\n newKey: JWK.Key\r\n ): Promise<ParentDirectoryInput> {\r\n // If directory's key is not already in the key graph, then need to\r\n // fetch the directory's key.\r\n const wrappingKey = await this.getDirectoryKey(\r\n options.directoryId,\r\n options.wrappingKeyId\r\n );\r\n\r\n return {\r\n directoryId: options.directoryId,\r\n wrappingKeyId: wrappingKey.id,\r\n wrappedKey: await this.keyGraph.wrapKey(wrappingKey, newKey),\r\n };\r\n }\r\n\r\n // async getKey(keyId: LrRelayIdInput, getKeyIdCallback: () => Promise<ID>) {\r\n // if (!this.keyGraph.hasKey(keyId)) {\r\n // keyId = await getKeyIdCallback();\r\n // }\r\n\r\n // return this.keyGraph.getKey(keyId);\r\n // }\r\n\r\n async getFileStateKeyId(fileStateNodeId: LrRelayIdInput) {\r\n return (\r\n await this.query({\r\n query: FileStateKeyQuery,\r\n variables: {\r\n id: fileStateNodeId,\r\n },\r\n })\r\n ).fileState.keyId;\r\n }\r\n\r\n async getDirectoryKeyId(directoryId: LrRelayIdInput) {\r\n return (\r\n await this.query({\r\n query: DirectoryKeyQuery,\r\n variables: {\r\n id: directoryId,\r\n },\r\n })\r\n ).directory.keyId;\r\n }\r\n\r\n async getFileKeyId(fileId: LrRelayIdInput) {\r\n return (\r\n await this.query({\r\n query: FileKeyQuery,\r\n variables: {\r\n id: fileId,\r\n },\r\n })\r\n ).file.keyId;\r\n }\r\n\r\n async getDirectoryKey(\r\n directoryId: LrRelayIdInput,\r\n directoryKeyId?: LrRelayIdInput\r\n ) {\r\n return this.keyGraph.getKey(directoryKeyId, () =>\r\n this.getDirectoryKeyId(directoryId)\r\n );\r\n }\r\n\r\n async getFileKey(fileId: LrRelayIdInput, fileKeyId?: LrRelayIdInput) {\r\n return this.keyGraph.getKey(fileKeyId, () => this.getFileKeyId(fileId));\r\n }\r\n\r\n private async getInput(\r\n key: JWK.Key,\r\n options: { plainMetaJson?: any; cipherMetaClearJson?: any }\r\n ) {\r\n const { plainMetaJson, cipherMetaClearJson } = options;\r\n\r\n return {\r\n plainMeta: plainMetaJson && JSON.stringify(plainMetaJson),\r\n cipherMeta:\r\n cipherMetaClearJson &&\r\n (await this.keyGraph.encryptToString(key, cipherMetaClearJson)),\r\n };\r\n }\r\n\r\n private async createFileState(\r\n fileKey: JWK.Key,\r\n options: CreateFileOptions | UpdateFileOptions\r\n ) {\r\n // Each version of the file is encrypted using a new key.\r\n const fileStateKey = await this.keyFactory.createKey();\r\n\r\n const fileContent =\r\n options.file && (await this.fileService.loadFile(options.file));\r\n\r\n let contentResource: string;\r\n if (fileContent) {\r\n const cipherFileContent = await this.keyGraph.encryptToString(\r\n fileStateKey,\r\n fileContent\r\n );\r\n if (options.upload) {\r\n contentResource = await options.upload(cipherFileContent);\r\n } else {\r\n contentResource = await this.fileService.uploadEncryptedFile({\r\n encryptedContent: cipherFileContent,\r\n });\r\n }\r\n console.log('contentResource', contentResource);\r\n }\r\n\r\n return {\r\n ...(await this.getInput(fileStateKey, options)),\r\n wrappedStateKey: await this.keyGraph.wrapKey(fileKey, fileStateKey),\r\n contentResource,\r\n };\r\n }\r\n\r\n archiveDirectory(directoryId: string, recursive: boolean) {\r\n return new LrMutation({\r\n mutation: ArchiveDirectoryMutation,\r\n variables: {\r\n input: {\r\n directoryId,\r\n recursive,\r\n },\r\n },\r\n });\r\n }\r\n\r\n unarchiveDirectory(directoryId: string, recursive: boolean) {\r\n return new LrMutation({\r\n mutation: UnarchiveDirectoryMutation,\r\n variables: {\r\n input: {\r\n directoryId,\r\n recursive,\r\n },\r\n },\r\n });\r\n }\r\n\r\n protected async getChangeItemParentsInput(\r\n options: ChangeItemParentsOptions,\r\n itemKey: JWK.Key\r\n ) {\r\n const parentsToAdd = await Promise.all(\r\n options.parentsToAdd.map((t) => this.getParentDirectoryInput(t, itemKey))\r\n );\r\n\r\n return {\r\n directoriesToRemove: options.parentsToRemove,\r\n directoriesToAdd: parentsToAdd,\r\n };\r\n }\r\n\r\n changeDirectoryParents(options: ChangeDirectoryParentsOptions) {\r\n return this.mutate(this.changeDirectoryParentsMutation(options));\r\n }\r\n\r\n async changeDirectoryParentsMutation(options: ChangeDirectoryParentsOptions) {\r\n const directoryKey = await this.getDirectoryKey(\r\n options.directoryId,\r\n options.directoryKeyId\r\n );\r\n\r\n return new LrMutation({\r\n mutation: ChangeDirectoryParentsMutation,\r\n variables: {\r\n input: {\r\n ...(await this.getChangeItemParentsInput(options, directoryKey.jwk)),\r\n directoryId: options.directoryId,\r\n },\r\n },\r\n });\r\n }\r\n\r\n async changeFileParents(options: ChangeFileParentsOptions) {\r\n return this.mutate(this.changeFileParentsMutation(options));\r\n }\r\n\r\n async changeFileParentsMutation(options: ChangeFileParentsOptions) {\r\n const fileKey = await this.getFileKey(options.fileId, options.fileKeyId);\r\n\r\n return new LrMutation({\r\n mutation: ChangeFileParentsMutation,\r\n variables: {\r\n input: {\r\n ...(await this.getChangeItemParentsInput(options, fileKey.jwk)),\r\n fileId: options.fileId,\r\n },\r\n },\r\n });\r\n }\r\n}\r\n","import gql from 'graphql-tag';\r\nimport { JWK } from 'node-jose';\r\nimport { gqlTyped } from '../_common/ast';\r\nimport {\r\n Connection,\r\n DateTime,\r\n ID,\r\n LrEmail,\r\n OtKeyCipherClearJson2,\r\n} from './types';\r\n\r\nexport type KeyExchangeState2 =\r\n | 'IN_PROGRESS'\r\n | 'COMPLETED'\r\n | 'DECLINED'\r\n | 'CANCELLED'\r\n | 'DELETED';\r\n\r\nexport interface KeyExchangeFragment {\r\n id: ID;\r\n token: string;\r\n state: KeyExchangeState2;\r\n mode: 'OTK';\r\n isInitiator: boolean;\r\n initiator: {\r\n id: ID;\r\n username: string;\r\n };\r\n responder: {\r\n id: ID;\r\n username: string;\r\n };\r\n created: DateTime;\r\n modified: DateTime;\r\n tokenExpiryTime: DateTime;\r\n isExpired: boolean;\r\n initiatorRootKeyCipher: string;\r\n initiatorRootKeyCipherClearJson: any;\r\n initiatorActionRequired: boolean;\r\n responderActionRequired: boolean;\r\n responderEmailAddress: LrEmail;\r\n otk: {\r\n state: 'OTK_INITIATED' | 'OTK_ACCEPTED' | 'OTK_COMPLETED';\r\n otKeyParams: string;\r\n otKeyCipher: string;\r\n otKey?: JWK.Key;\r\n otKeyCipherClearJson?: OtKeyCipherClearJson2;\r\n sharedKey: {\r\n id: ID;\r\n };\r\n mkSharedKey: {\r\n id: ID;\r\n };\r\n initiatorSigPxk: {\r\n id: ID;\r\n };\r\n responderSigPxk: {\r\n id: ID;\r\n };\r\n initiatorOneTimePbkCipher: string;\r\n initiatorOneTimePbkCipherClearJson: any;\r\n responderPbkCipher: string;\r\n };\r\n}\r\nexport const KeyExchangeFragment = gqlTyped<KeyExchangeFragment>`\r\nfragment KeyExchangeFragment on KeyExchangeNode {\r\n id\r\n token\r\n state\r\n mode\r\n isInitiator\r\n initiator {\r\n id\r\n username\r\n }\r\n responder {\r\n id\r\n username\r\n }\r\n created\r\n modified\r\n tokenExpiryTime\r\n isExpired\r\n initiatorRootKeyCipher\r\n initiatorActionRequired\r\n responderActionRequired\r\n responderEmailAddress\r\n otk {\r\n state\r\n otKeyParams\r\n otKeyCipher\r\n sharedKey {\r\n id\r\n }\r\n mkSharedKey {\r\n id\r\n }\r\n initiatorSigPxk {\r\n id\r\n }\r\n responderSigPxk {\r\n id\r\n }\r\n initiatorOneTimePbkCipher\r\n responderPbkCipher\r\n }\r\n}\r\n`;\r\n\r\nexport interface UserSharedKeyFragment {\r\n userSigPrk: {\r\n id: ID;\r\n };\r\n otherSigPbk: {\r\n id: ID;\r\n };\r\n sharedKey: {\r\n id: ID;\r\n };\r\n mkSharedKey: {\r\n id: ID;\r\n };\r\n}\r\nexport const UserSharedKeyFragment = gqlTyped<UserSharedKeyFragment>`\r\nfragment UserSharedKeyFragment on UserSharedKeyNode {\r\n userSigPrk {\r\n id\r\n }\r\n otherSigPbk {\r\n id\r\n }\r\n sharedKey {\r\n id\r\n }\r\n mkSharedKey {\r\n id\r\n }\r\n}`;\r\n\r\nexport interface KeyExchangesQuery2 {\r\n keyExchanges: Connection<KeyExchangeFragment>;\r\n}\r\nexport const KeyExchangesQuery2 = gqlTyped<KeyExchangesQuery2>`\r\nquery KeyExchangesQuery2($state: String) {\r\n keyExchanges(state: $state) {\r\n edges {\r\n node {\r\n ...KeyExchangeFragment\r\n }\r\n }\r\n }\r\n}\r\n${KeyExchangeFragment}\r\n`;\r\n\r\nexport interface KeyExchangeQuery2 {\r\n keyExchange: KeyExchangeFragment;\r\n}\r\nexport const KeyExchangeQuery2 = gqlTyped<KeyExchangeQuery2>`\r\nquery KeyExchangeQuery2($id: LrRelayIdInput!) {\r\n keyExchange(id: $id) {\r\n ...KeyExchangeFragment\r\n }\r\n}\r\n${KeyExchangeFragment}\r\n`;\r\n\r\n// Key graph is only available for authenticated users. This query\r\n// is for unauthenticated users.\r\nexport interface KeyExchangeTokenQuery2 {\r\n keyExchange: KeyExchangeFragment;\r\n}\r\nexport const KeyExchangeTokenQuery2 = gqlTyped<KeyExchangeTokenQuery2>`\r\nquery KeyExchangeTokenQuery2($id: LrRelayIdInput!, $token: String) {\r\n keyExchange(id: $id, token: $token) {\r\n ...KeyExchangeFragment\r\n }\r\n}\r\n${KeyExchangeFragment}\r\n`;\r\n\r\nexport interface CancelKeyExchangeMutation {\r\n cancelKeyExchange: {\r\n keyExchange: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const CancelKeyExchangeMutation = gqlTyped<CancelKeyExchangeMutation>`\r\nmutation CancelKeyExchangeMutation($input: CancelKeyExchangeInput!) {\r\n cancelKeyExchange(input: $input) {\r\n keyExchange {\r\n id\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport interface DeclineKeyExchangeMutation {\r\n declineKeyExchange: {\r\n keyExchange: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const DeclineKeyExchangeMutation = gqlTyped<DeclineKeyExchangeMutation>`\r\nmutation DeclineKeyExchangeMutation($input: DeclineKeyExchangeInput!) {\r\n declineKeyExchange(input: $input) {\r\n keyExchange {\r\n id\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport interface InitiateKeyExchangeOtkMutation {\r\n initiateKeyExchangeOtk: {\r\n keyExchange: KeyExchangeFragment;\r\n };\r\n}\r\nexport const InitiateKeyExchangeOtkMutation = gqlTyped<InitiateKeyExchangeOtkMutation>`\r\nmutation InitiateKeyExchangeOtkMutation(\r\n $input: InitiateKeyExchangeOtkInput!\r\n) {\r\n initiateKeyExchangeOtk(input: $input) {\r\n keyExchange {\r\n ...KeyExchangeFragment\r\n }\r\n }\r\n}\r\n${KeyExchangeFragment}\r\n`;\r\n\r\nexport interface RespondKeyExchangeOtkMutation {\r\n respondKeyExchangeOtk: {\r\n keyExchange: KeyExchangeFragment;\r\n userSharedKey: UserSharedKeyFragment;\r\n tp: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const RespondKeyExchangeOtkMutation = gqlTyped<RespondKeyExchangeOtkMutation>`\r\nmutation RespondKeyExchangeOtkMutation($input: RespondKeyExchangeOtkInput!) {\r\n respondKeyExchangeOtk(input: $input) {\r\n keyExchange {\r\n ...KeyExchangeFragment\r\n }\r\n userSharedKey {\r\n ...UserSharedKeyFragment\r\n }\r\n tp {\r\n id\r\n }\r\n }\r\n}\r\n${KeyExchangeFragment}\r\n${UserSharedKeyFragment}\r\n`;\r\n\r\nexport interface CompleteKeyExchangeOtkMutation {\r\n completeKeyExchangeOtk: {\r\n keyExchange: KeyExchangeFragment;\r\n userSharedKey: UserSharedKeyFragment;\r\n tp: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const CompleteKeyExchangeOtkMutation = gqlTyped<CompleteKeyExchangeOtkMutation>`\r\nmutation CompleteKeyExchangeOtkMutation(\r\n $input: CompleteKeyExchangeOtkInput!\r\n) {\r\n completeKeyExchangeOtk(input: $input) {\r\n keyExchange {\r\n ...KeyExchangeFragment\r\n }\r\n userSharedKey {\r\n ...UserSharedKeyFragment\r\n }\r\n tp {\r\n id\r\n }\r\n }\r\n}\r\n${KeyExchangeFragment}\r\n${UserSharedKeyFragment}\r\n`;\r\n\r\nexport interface CurrentUserSharedKeyQuery2 {\r\n currentUserSharedKey: {\r\n userSharedKey: UserSharedKeyFragment;\r\n };\r\n}\r\nexport const CurrentUserSharedKeyQuery2 = gqlTyped<CurrentUserSharedKeyQuery2>`\r\nquery CurrentUserSharedKeyQuery2(\r\n $username: String\r\n $userId: LrRelayIdInput\r\n) {\r\n currentUserSharedKey(\r\n username: $username\r\n userId: $userId\r\n ) {\r\n userSharedKey {\r\n ...UserSharedKeyFragment\r\n }\r\n }\r\n}\r\n${UserSharedKeyFragment}\r\n`;\r\n","import { Injectable, NgZone } from '@angular/core';\r\nimport { JWK } from 'node-jose';\r\nimport {\r\n EncryptionService,\r\n JoseSerialization,\r\n} from '../cryptography/encryption.service';\r\nimport { KeyFactoryService } from '../cryptography/key-factory.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport { LrCodeMismatchException } from '../_common/exceptions';\r\nimport { RunOutsideAngular } from '../_common/run-outside-angular';\r\nimport { UserService } from './../users/user.service';\r\nimport { OwnerPlainDataJson } from './contact-card2.service';\r\nimport {\r\n CancelKeyExchangeMutation,\r\n CompleteKeyExchangeOtkMutation,\r\n CurrentUserSharedKeyQuery2,\r\n DeclineKeyExchangeMutation,\r\n InitiateKeyExchangeOtkMutation,\r\n KeyExchangeFragment,\r\n KeyExchangeQuery2,\r\n KeyExchangesQuery2,\r\n KeyExchangeState2,\r\n KeyExchangeTokenQuery2,\r\n RespondKeyExchangeOtkMutation,\r\n} from './key-exchange2.gql';\r\nimport { LrGraphQLService, LrMutation } from './lr-graphql';\r\nimport { ContactCardSharedCipherData, OtKeyCipherClearJson2 } from './types';\r\n\r\n/**\r\n * The decrypted content of the one-time key cipher;\r\n * When user supplies this information the lib doesn't need to do another API call\r\n * to fetch the key exchange node. And since the typical use case is to display\r\n * some information to the user, the key exchange node would already have been\r\n * fetched and decrypted.\r\n */\r\nexport interface DecryptedOtk2 {\r\n otKeyCipherClearJson: OtKeyCipherClearJson2;\r\n otKey: JWK.Key; // The one-time key\r\n}\r\n\r\nexport interface ContactCardReceiverCipherData {\r\n // The receiver of the contact card keeps a copy\r\n // of the owner's contact card information, encrypted using the receiver's keys. So that when\r\n // the owner decides to update their shared contact card at a later date, the receiver can\r\n // compare against the original contact card sent during key exchange. This way, the owner\r\n // can't unilaterally update their shared contact card without the receiver knowing about it.\r\n receiverCipherDataClearJson: any;\r\n}\r\n\r\nexport interface ContactCardOwnerPlainData {\r\n // Accessible by the server and the owner. Server side notification emails need to know some\r\n // information about the owner.\r\n // The owner could either be the initiator or the responder.\r\n ownerPlainDataJson: OwnerPlainDataJson;\r\n}\r\n\r\nexport interface ContactCardOwnerCipherData {\r\n // Owner only access to this data\r\n ownerCipherDataClearJson: any;\r\n}\r\n\r\n/**\r\n * Sending contact card information from the owner to the receiver.\r\n */\r\nexport type SendContactCardInput = ContactCardOwnerPlainData &\r\n ContactCardOwnerCipherData &\r\n ContactCardSharedCipherData;\r\n\r\nexport interface InitiateOtkInput2 {\r\n // Note that if neither email nor responderUsername are given, the one-time key\r\n // can still be sent to the responder via OOB\r\n email?: string;\r\n message?: any;\r\n contactCard?: SendContactCardInput;\r\n // If True, to upgrade an email invite to an existing user invite if the email\r\n // is already associated with an existing user.\r\n upgrade?: boolean;\r\n}\r\n\r\nexport interface RespondOtkInput2 {\r\n keyExchangeId: string;\r\n token: string;\r\n decryptedOtk: DecryptedOtk2;\r\n message?: any;\r\n // The initiator is the owner fo the initiatorContactCard, the responder\r\n // is the receiver.\r\n initiatorContactCard?: ContactCardReceiverCipherData;\r\n responderContactCard?: SendContactCardInput;\r\n}\r\n\r\nexport interface CompleteOtkInput2 {\r\n keyExchangeId: string;\r\n // This is a part of the key exchange data. It's encrypted using the root key\r\n initiatorRootKeyCipher: string;\r\n // This is a part of the key exchange data. It's encrypted using the one-time key.\r\n initiatorOneTimePbkCipher: string;\r\n // The responder is the owner fo the responderContactCard, the initiator\r\n // is the receiver.\r\n responderContactCard?: ContactCardReceiverCipherData;\r\n // The initiator can update the cipher data that are only visible to them. It makes\r\n // less sense to update the shared data because the responder would have already seen\r\n // the shared data and accepted that it's legit.\r\n // But in any case, the initiator can update the shared contact card info at any time.\r\n initiatorContactCard?: ContactCardOwnerCipherData;\r\n}\r\n\r\nexport interface InitiatorRootKeyCipherClearJson2 {\r\n nonce: string;\r\n oneTimePrk: object; // one-time public encryption key responder use to send data back to initiator\r\n otKey: object; // one-time symmetric key that needs to be shared OOB\r\n initiatorContactCard?: ContactCardOwnerCipherData &\r\n ContactCardSharedCipherData;\r\n initiator: {\r\n message?: any;\r\n contactCard?: ContactCardSharedCipherData;\r\n };\r\n}\r\n\r\nexport interface InitiatorOneTimePbkCipherClearJson {\r\n nonce: string;\r\n sharedKey: object;\r\n mkSharedKey: object;\r\n responder: {\r\n pbk: object;\r\n sigPbk: object;\r\n message?: any;\r\n contactCard?: ContactCardSharedCipherData & {\r\n // Note that this is _not_ the same key as the sharedKey. The sharedKey wraps\r\n // this key in the key graph. But because this key has not been entered into\r\n // the key graph when the responder calls the API, we pass the JWK directly here.\r\n sharedCipherKey: object;\r\n };\r\n };\r\n}\r\n\r\nexport interface GetKeyExchangeOptions2 {\r\n // The otKey as a raw string. i.e. key.toJSON(true).k\r\n otKeyK?: string;\r\n // User need the token if they have not responded to the key exchange yet.\r\n // Once they've responded (hence proven they have the OOB Key) they become\r\n // the \"responder\" of this exchange, and can access it when signed in.\r\n token?: string;\r\n}\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class KeyExchange2Service {\r\n private readonly CLIENT_NONCE_LENGTH = 32;\r\n\r\n constructor(\r\n private ngZone: NgZone,\r\n private keyFactory: KeyFactoryService,\r\n private keyService: KeyService,\r\n private encryptionService: EncryptionService,\r\n private userService: UserService,\r\n private keyGraph: KeyGraphService,\r\n private lrGraphQL: LrGraphQLService\r\n ) {}\r\n\r\n private async getOtKey(\r\n keyExchange: KeyExchangeFragment,\r\n otKeyK?: string\r\n ): Promise<JWK.Key> {\r\n if (otKeyK) {\r\n return await KeyFactoryService.asKey({\r\n ...JSON.parse(keyExchange.otk.otKeyParams),\r\n k: otKeyK,\r\n });\r\n } else if (\r\n keyExchange.otk.state === 'OTK_INITIATED' &&\r\n !keyExchange.isInitiator &&\r\n keyExchange.otk.responderPbkCipher\r\n ) {\r\n // Assuming existing user getting invited where OTK is wrapped in responder's public key.\r\n const prk = await this.keyService.getCurrentPxk();\r\n const decryptedCipher: any = await this.encryptionService.decrypt(\r\n prk.jwk,\r\n JSON.parse(keyExchange.otk.responderPbkCipher),\r\n {\r\n serializations: [JoseSerialization.COMPACT],\r\n }\r\n );\r\n if (decryptedCipher.otKey) {\r\n return await KeyFactoryService.asKey(decryptedCipher.otKey);\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n private async decryptOtk(\r\n keyExchange: KeyExchangeFragment,\r\n otKeyK?: string\r\n ): Promise<KeyExchangeFragment> {\r\n const otKey = await this.getOtKey(keyExchange, otKeyK);\r\n\r\n let otk = keyExchange.otk;\r\n\r\n if (otKey && otk.otKeyCipher) {\r\n otk = {\r\n ...otk,\r\n otKey,\r\n otKeyCipherClearJson: await this.encryptionService.decrypt(\r\n otKey,\r\n keyExchange.otk.otKeyCipher\r\n ),\r\n };\r\n }\r\n\r\n return {\r\n ...keyExchange,\r\n otk,\r\n };\r\n }\r\n\r\n private async decryptResponseCipher(\r\n otKey: JWK.Key,\r\n otPrk: JWK.Key,\r\n content: any\r\n ): Promise<InitiatorOneTimePbkCipherClearJson> {\r\n // The response could be wrapped by the OtK in addition to the OtPbk\r\n try {\r\n content = await this.encryptionService.decrypt(otKey, content);\r\n } catch (error) {\r\n if (error.message !== 'no key found') {\r\n throw error;\r\n }\r\n // Do nothing to support older versions where message is not wrapped with otk.\r\n }\r\n\r\n // The Prk is single-use and only used to send information from the responder back to the initiator.\r\n return await this.encryptionService.decrypt(otPrk, content);\r\n }\r\n\r\n private async decryptKeyExchangeAsInitiator(\r\n keyExchange: KeyExchangeFragment\r\n ): Promise<KeyExchangeFragment> {\r\n const rootKey = await this.keyService.getCurrentRootKey();\r\n\r\n // Decrypt using the root key to get the Prk\r\n const initiatorRootKeyCipherClearJson = (await this.encryptionService.decrypt(\r\n rootKey.jwk,\r\n keyExchange.initiatorRootKeyCipher\r\n )) as InitiatorRootKeyCipherClearJson2;\r\n\r\n const otKey = await KeyFactoryService.asKey(\r\n initiatorRootKeyCipherClearJson.otKey\r\n );\r\n\r\n keyExchange = {\r\n ...keyExchange,\r\n initiatorRootKeyCipherClearJson,\r\n };\r\n\r\n let otk = keyExchange.otk;\r\n\r\n if (otk.initiatorOneTimePbkCipher) {\r\n otk = {\r\n ...otk,\r\n initiatorOneTimePbkCipherClearJson: await this.decryptResponseCipher(\r\n otKey,\r\n await KeyFactoryService.asKey(\r\n initiatorRootKeyCipherClearJson.oneTimePrk\r\n ),\r\n otk.initiatorOneTimePbkCipher\r\n ),\r\n };\r\n }\r\n\r\n if (otk.otKeyCipher) {\r\n otk.otKeyCipherClearJson = await this.encryptionService.decrypt(\r\n otKey,\r\n otk.otKeyCipher\r\n );\r\n }\r\n\r\n return {\r\n ...keyExchange,\r\n otk,\r\n };\r\n }\r\n\r\n private async decryptKeyExchangeAsResponder(\r\n keyExchange: KeyExchangeFragment,\r\n otKeyK?: string\r\n ) {\r\n return this.decryptOtk(keyExchange, otKeyK);\r\n }\r\n\r\n async decryptKeyExchange(keyExchange: KeyExchangeFragment, otKeyK?: string) {\r\n if (keyExchange.isInitiator) {\r\n return this.decryptKeyExchangeAsInitiator(keyExchange);\r\n } else {\r\n return this.decryptKeyExchangeAsResponder(keyExchange, otKeyK);\r\n }\r\n }\r\n\r\n async getKeyExchanges({ state }: { state?: KeyExchangeState2 } = {}) {\r\n const { keyExchanges } = await this.lrGraphQL.query({\r\n query: KeyExchangesQuery2,\r\n variables: {\r\n state,\r\n },\r\n });\r\n\r\n return Promise.all(\r\n keyExchanges.edges.map((edge) => this.decryptKeyExchange(edge.node))\r\n );\r\n }\r\n\r\n /**\r\n * @param id If the current user can responder the key exchange if they are either the initiator or the receiver.\r\n * @param token If not signed in, or not the initiator or responder, 'token' must be given.\r\n * @param otKeyK Is the raw one-time key (string). If the responder is explicitly specified at time of initiation, then\r\n * it's possible to have the otKey wrapped by the public key of the responder. In which case, the otKeyK is not needed.\r\n */\r\n async getKeyExchange(\r\n id: string,\r\n { otKeyK, token }: GetKeyExchangeOptions2 = {}\r\n ) {\r\n const res = await this.lrGraphQL.query({\r\n query: token ? KeyExchangeTokenQuery2 : KeyExchangeQuery2,\r\n variables: {\r\n id,\r\n token,\r\n },\r\n includeKeyGraph: !token, // if !token then we are post auth, so can fetch keyGraph\r\n });\r\n return this.decryptKeyExchange(res.keyExchange, otKeyK);\r\n }\r\n\r\n public async getCurrentUserSharedKey(input: {\r\n username?: string;\r\n userId?: string;\r\n }) {\r\n return this.lrGraphQL.query({\r\n query: CurrentUserSharedKeyQuery2,\r\n variables: {\r\n username: input.username,\r\n userId: input.userId,\r\n },\r\n });\r\n }\r\n\r\n // TODO: deprecate this\r\n async cancelKeyExchange(id: string) {\r\n return this.cancelKeyExchangeMutation(id);\r\n }\r\n\r\n cancelKeyExchangeMutation(id: string) {\r\n return new LrMutation({\r\n mutation: CancelKeyExchangeMutation,\r\n variables: {\r\n input: {\r\n id,\r\n },\r\n },\r\n });\r\n }\r\n\r\n // TODO: deprecate this\r\n async declineKeyExchange(id: string, token: string) {\r\n return this.declineKeyExchangeMutation(id, token);\r\n }\r\n\r\n declineKeyExchangeMutation(id: string, token: string) {\r\n return new LrMutation({\r\n mutation: DeclineKeyExchangeMutation,\r\n variables: {\r\n input: {\r\n id,\r\n token,\r\n },\r\n },\r\n });\r\n }\r\n\r\n async initiateOtk({\r\n message,\r\n email,\r\n contactCard,\r\n upgrade,\r\n }: InitiateOtkInput2 = {}) {\r\n const otKey = await this.keyFactory.createKey();\r\n const nonce = this.keyFactory.randomString(this.CLIENT_NONCE_LENGTH);\r\n\r\n // New PKC key for encryption. This key is used only once when the responder sends\r\n // back their signing public key.\r\n const initiatorOneTimePrk = await this.keyFactory.createPkcKey();\r\n\r\n // Option 1: New PKC key for signing\r\n // const initiatorSigPrk = await this.keyService.createPkcSignKey();\r\n\r\n // Option 2: Use the user's global signing key.\r\n // This key is used to prove the initiator's identity.\r\n const initiatorPrk = await this.keyService.getCurrentPxk();\r\n const initiatorSigPrk = await this.keyService.getCurrentSigPxk();\r\n\r\n let initiatorPlainDataSig: string = null;\r\n\r\n if (contactCard && contactCard.ownerPlainDataJson) {\r\n initiatorPlainDataSig = await this.encryptionService.signToString(\r\n initiatorSigPrk.jwk,\r\n contactCard.ownerPlainDataJson\r\n );\r\n }\r\n\r\n const initiator = {\r\n message,\r\n contactCard: contactCard && {\r\n sharedCipherDataClearJson: contactCard.sharedCipherDataClearJson,\r\n },\r\n };\r\n\r\n // Content to be encrypted using the OTK.\r\n const plainOtKeyCipher: OtKeyCipherClearJson2 = {\r\n // TODO Make sure we also put the OOB code in here as well since the OOB code is the\r\n // _only_ information the KC server does not have access to. The server may have\r\n // access to OTK and hence the nonce here. It's good to have both the nonce and OOB code\r\n // since the user may not be using the OOB code. And it's simple to always include\r\n // the nonce, so why not.\r\n nonce,\r\n initiator: {\r\n ...initiator,\r\n oneTimePbk: initiatorOneTimePrk.toJSON(), // one-time public encryption key responder use to send data back to initiator\r\n pbk: initiatorPrk.jwk.toJSON(), // public encryption key\r\n sigPbk: initiatorSigPrk.jwk.toJSON(), // public signing key\r\n },\r\n };\r\n\r\n const otKeyCipher = await this.keyGraph.encryptToString(\r\n otKey,\r\n plainOtKeyCipher\r\n );\r\n\r\n // Content to be encrypted using the initiator's root key.\r\n const initiatorRootKeyCipherClearJson: InitiatorRootKeyCipherClearJson2 = {\r\n nonce,\r\n oneTimePrk: initiatorOneTimePrk.toJSON(true),\r\n // Should not need to keep this encrypted since we are using the global signing key.\r\n // sigPrk: initiatorSigPrk.toJSON(true),\r\n\r\n // Save it in case the initiator want to decode the otKeyCipher.\r\n // Since the otKey is only used once, and that otKeyCipher contains only\r\n // the public key of the initiator, it's safe just leave the otKey stored here.\r\n otKey: otKey.toJSON(true),\r\n // These should be storing information such as how the fields of the shared contact card is\r\n // derived from the master contact card.\r\n initiatorContactCard: contactCard,\r\n initiator,\r\n };\r\n\r\n const rootKey = await this.keyService.getCurrentRootKey();\r\n const initiatorRootKeyCipher = await this.keyGraph.encryptToString(\r\n rootKey.jwk,\r\n initiatorRootKeyCipherClearJson\r\n );\r\n\r\n // The raw OTK\r\n const otKeyK: string = (otKey.toJSON(true) as any).k;\r\n\r\n // API call\r\n const lrMutation = new LrMutation({\r\n mutation: InitiateKeyExchangeOtkMutation,\r\n variables: {\r\n input: {\r\n // These will be stored on the server\r\n initiatorRootKeyCipher,\r\n initiatorPxkId: initiatorPrk.id,\r\n initiatorSigPxkId: initiatorSigPrk.id,\r\n // These will be sent to the responder\r\n otKeyParams: JSON.stringify(otKey.toJSON()),\r\n otKeyCipher,\r\n sendEmail: email && {\r\n email,\r\n rawOtKey: otKeyK,\r\n },\r\n createTp: true,\r\n initiatorPlainDataSig,\r\n upgrade,\r\n },\r\n },\r\n });\r\n\r\n return { lrMutation, otKeyK };\r\n }\r\n\r\n async respondOtk({\r\n keyExchangeId,\r\n token,\r\n decryptedOtk,\r\n message,\r\n initiatorContactCard,\r\n responderContactCard,\r\n }: RespondOtkInput2) {\r\n const rootKey = await this.keyService.getCurrentRootKey();\r\n\r\n const masterKeyId = this.keyService.getCurrentMasterKey().id;\r\n const masterKey = await this.keyService.getCurrentMasterKey();\r\n\r\n const sharedKey = await this.keyFactory.createKey();\r\n const mkSharedKey = await this.keyFactory.createKey();\r\n\r\n const rkWrappedSharedKey = await this.encryptionService.encrypt(\r\n rootKey.jwk,\r\n sharedKey.toJSON(true)\r\n );\r\n const mkWrappedMkSharedKey = await this.encryptionService.encrypt(\r\n masterKey.jwk,\r\n mkSharedKey.toJSON(true)\r\n );\r\n\r\n const initiatorOneTimePbk = await KeyFactoryService.asKey(\r\n decryptedOtk.otKeyCipherClearJson.initiator.oneTimePbk\r\n );\r\n\r\n const initiatorPbk = await KeyFactoryService.asKey(\r\n decryptedOtk.otKeyCipherClearJson.initiator.pbk\r\n );\r\n const initiatorSigPbk = await KeyFactoryService.asKey(\r\n decryptedOtk.otKeyCipherClearJson.initiator.sigPbk\r\n );\r\n\r\n // Option 1: Using new Prk for each TP pair\r\n // Create a new public signing key for the responder.\r\n // const responderSigPrk = await this.keyService.createPkcSignKey()\r\n // const rkWrappedResponderSigPrk = await this.encrypt(rootKey, responderSigPrk.toJSON(true));\r\n\r\n // Option 2: Responder already has a signing Prk\r\n const responderPrk = await this.keyService.getCurrentPxk();\r\n const responderSigPrk = await this.keyService.getCurrentSigPxk();\r\n\r\n const signedInitiatorPbk = await this.encryptionService.sign(\r\n responderSigPrk.jwk,\r\n initiatorPbk.toJSON()\r\n );\r\n const signedInitiatorSigPbk = await this.encryptionService.sign(\r\n responderSigPrk.jwk,\r\n initiatorSigPbk.toJSON()\r\n );\r\n\r\n const initiatorOneTimePbkCipherClearJson: InitiatorOneTimePbkCipherClearJson = {\r\n nonce: decryptedOtk.otKeyCipherClearJson.nonce,\r\n sharedKey: sharedKey.toJSON(true),\r\n mkSharedKey: mkSharedKey.toJSON(true),\r\n responder: {\r\n pbk: responderPrk.jwk.toJSON(), // public key\r\n sigPbk: responderSigPrk.jwk.toJSON(), // public key\r\n message,\r\n },\r\n };\r\n\r\n let receivedCardInput;\r\n if (decryptedOtk.otKeyCipherClearJson.initiator.contactCard) {\r\n // Set the info about the initiator to be the ones sent by the initiator. We need th responder to do the encryption here\r\n // because the initiator does not have the shared key yet, and we want the responder to have a functional contact card after\r\n // this exchange. The initiator can double check the contact details are correct and sign it when it completes the exchange.\r\n const sharedCipherDataClearJson =\r\n decryptedOtk.otKeyCipherClearJson.initiator.contactCard\r\n .sharedCipherDataClearJson;\r\n\r\n // Create keys\r\n const receiverKey = await this.keyFactory.createKey();\r\n const ccSharedKey = await this.keyFactory.createKey();\r\n const sigPxk = await this.keyService.getCurrentSigPxk();\r\n\r\n receivedCardInput = {\r\n receiverWrappedKey: JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n rootKey.jwk,\r\n receiverKey.toJSON(true)\r\n )\r\n ),\r\n receiverWrappingKeyId: rootKey.id,\r\n receiverCipherData: initiatorContactCard\r\n ? JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n receiverKey,\r\n initiatorContactCard.receiverCipherDataClearJson\r\n )\r\n )\r\n : '',\r\n sharedWrappedKey: JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n sharedKey,\r\n ccSharedKey.toJSON(true)\r\n )\r\n ),\r\n };\r\n\r\n const sharedCipherData = await this.encryptionService.encrypt(\r\n ccSharedKey,\r\n sharedCipherDataClearJson\r\n );\r\n receivedCardInput.sharedCipherDataSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, sharedCipherData)\r\n );\r\n receivedCardInput.sigPxkId = sigPxk.id;\r\n\r\n initiatorOneTimePbkCipherClearJson.responder.contactCard = {\r\n ...initiatorOneTimePbkCipherClearJson.responder.contactCard,\r\n sharedCipherKey: ccSharedKey.toJSON(true),\r\n };\r\n }\r\n\r\n let responderCardInput;\r\n if (responderContactCard) {\r\n // Create keys\r\n const ownerKey = await this.keyFactory.createKey();\r\n const ccSharedKey = await this.keyFactory.createKey();\r\n const sigPxk = await this.keyService.getCurrentSigPxk();\r\n\r\n responderCardInput = {\r\n ownerWrappedKey: JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n rootKey.jwk,\r\n ownerKey.toJSON(true)\r\n )\r\n ),\r\n ownerWrappingKeyId: rootKey.id,\r\n ownerCipherData: responderContactCard.ownerCipherDataClearJson\r\n ? JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n ownerKey,\r\n responderContactCard.ownerCipherDataClearJson\r\n )\r\n )\r\n : '',\r\n\r\n sharedWrappedKey: JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n sharedKey,\r\n ccSharedKey.toJSON(true)\r\n )\r\n ),\r\n };\r\n\r\n const sharedCipherData = await this.encryptionService.encrypt(\r\n ccSharedKey,\r\n responderContactCard.sharedCipherDataClearJson\r\n );\r\n responderCardInput.sharedCipherDataSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, sharedCipherData)\r\n );\r\n responderCardInput.sigPxkId = sigPxk.id;\r\n\r\n if (responderContactCard.ownerPlainDataJson) {\r\n responderCardInput.ownerPlainDataSig = JSON.stringify(\r\n await this.encryptionService.sign(\r\n responderSigPrk.jwk,\r\n responderContactCard.ownerPlainDataJson\r\n )\r\n );\r\n }\r\n\r\n // Contact card info readable by the initiator\r\n initiatorOneTimePbkCipherClearJson.responder.contactCard = {\r\n ...initiatorOneTimePbkCipherClearJson.responder.contactCard,\r\n sharedCipherDataClearJson:\r\n responderContactCard.sharedCipherDataClearJson,\r\n };\r\n }\r\n\r\n // Encrypt with one-time public key\r\n let initiatorOneTimePbkCipher = await this.encryptionService.encrypt(\r\n initiatorOneTimePbk,\r\n initiatorOneTimePbkCipherClearJson\r\n );\r\n\r\n // Encrypt with the otk again to keep use of asymmetric keys to a minimum.\r\n initiatorOneTimePbkCipher = await this.encryptionService.encrypt(\r\n decryptedOtk.otKey,\r\n initiatorOneTimePbkCipher\r\n );\r\n\r\n return new LrMutation({\r\n mutation: RespondKeyExchangeOtkMutation,\r\n variables: {\r\n input: {\r\n keyExchangeId,\r\n keyExchangeToken: token,\r\n rootKeyId: rootKey.id,\r\n masterKeyId,\r\n // These will be stored on the server\r\n responderPxkId: responderPrk.id,\r\n responderSigPxkId: responderSigPrk.id,\r\n signedInitiatorPbk: JSON.stringify(signedInitiatorPbk),\r\n signedInitiatorSigPbk: JSON.stringify(signedInitiatorSigPbk),\r\n // rkWrappedInitiatorSigPbk: JSON.stringify(rkWrappedInitiatorSigPbk),\r\n\r\n // Option 1: Using new Prk for each TP pair\r\n // rkWrappedResponderSigPrk: JSON.stringify(rkWrappedResponderSigPrk),\r\n rkWrappedSharedKey: JSON.stringify(rkWrappedSharedKey),\r\n mkWrappedMkSharedKey: JSON.stringify(mkWrappedMkSharedKey),\r\n // These will be sent to the initiator\r\n initiatorOneTimePbkCipher: JSON.stringify(initiatorOneTimePbkCipher),\r\n initiatorContactCard: receivedCardInput,\r\n responderContactCard: responderCardInput,\r\n },\r\n },\r\n });\r\n }\r\n\r\n async completeOtk({\r\n keyExchangeId,\r\n initiatorRootKeyCipher,\r\n initiatorOneTimePbkCipher,\r\n responderContactCard,\r\n initiatorContactCard,\r\n }: CompleteOtkInput2) {\r\n const rootKey = await this.keyService.getCurrentRootKey();\r\n const masterKey = await this.keyService.getCurrentMasterKey();\r\n\r\n // Decrypt using the root key to get the Prk\r\n const initiatorRootKeyCipherClearJson = (await this.encryptionService.decrypt(\r\n rootKey.jwk,\r\n initiatorRootKeyCipher\r\n )) as InitiatorRootKeyCipherClearJson2;\r\n\r\n // The Prk is single-use and only used to send information from the responder back to the initiator.\r\n const plainInitiatorOneTimePbkCipher = await this.decryptResponseCipher(\r\n await KeyFactoryService.asKey(initiatorRootKeyCipherClearJson.otKey),\r\n await KeyFactoryService.asKey(initiatorRootKeyCipherClearJson.oneTimePrk),\r\n initiatorOneTimePbkCipher\r\n );\r\n\r\n // Check the nonce match to ensure the responder was the one holding the OTK\r\n if (\r\n initiatorRootKeyCipherClearJson.nonce !==\r\n plainInitiatorOneTimePbkCipher.nonce\r\n ) {\r\n throw new LrCodeMismatchException(\r\n 'The nonce returned by responder does not match with the one created by the initiator.'\r\n );\r\n }\r\n\r\n // Option 1: Assuming the signing key is unique between users.\r\n // const initiatorSigPrk = await KFS.asKey(ke.plainInitiatorRootKeyCipher.sigPrk);\r\n // const rkWrappedInitiatorSigPrk = await this.encrypt(rootKey, initiatorSigPrk.toJSON(true));\r\n\r\n // Option 2: Use the user's global signing key.\r\n // In this case the initiatorSigPrk is already a part of the key graph.\r\n // So there's nothing to do here.\r\n\r\n // Protected the signing public key of the responder.\r\n const initiatorSigPrk = await this.keyService.getCurrentSigPxk();\r\n const responderSigPbk = await KeyFactoryService.asKey(\r\n plainInitiatorOneTimePbkCipher.responder.sigPbk\r\n );\r\n const responderPbk = await KeyFactoryService.asKey(\r\n plainInitiatorOneTimePbkCipher.responder.pbk\r\n );\r\n\r\n const signedResponderPbk = await this.encryptionService.sign(\r\n initiatorSigPrk.jwk,\r\n responderPbk.toJSON()\r\n );\r\n const signedResponderSigPbk = await this.encryptionService.sign(\r\n initiatorSigPrk.jwk,\r\n responderSigPbk.toJSON()\r\n );\r\n\r\n const sharedKey = await KeyFactoryService.asKey(\r\n plainInitiatorOneTimePbkCipher.sharedKey\r\n );\r\n const rkWrappedSharedKey = await this.encryptionService.encrypt(\r\n rootKey.jwk,\r\n sharedKey.toJSON(true)\r\n );\r\n\r\n const mkSharedKey = await KeyFactoryService.asKey(\r\n plainInitiatorOneTimePbkCipher.mkSharedKey\r\n );\r\n const mkWrappedMkSharedKey = await this.encryptionService.encrypt(\r\n masterKey.jwk,\r\n mkSharedKey.toJSON(true)\r\n );\r\n\r\n let responderContactCardCipherInput;\r\n if (responderContactCard) {\r\n // Create key\r\n const receiverKey = await this.keyFactory.createKey();\r\n\r\n responderContactCardCipherInput = {\r\n receiverWrappedKey: JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n rootKey.jwk,\r\n receiverKey.toJSON(true)\r\n )\r\n ),\r\n receiverWrappingKeyId: rootKey.id,\r\n receiverCipherData: JSON.stringify(\r\n await this.encryptionService.encrypt(\r\n receiverKey,\r\n responderContactCard.receiverCipherDataClearJson\r\n )\r\n ),\r\n };\r\n }\r\n\r\n // Get the data needed from the initiator's cipher data.\r\n let initiatorContactCardCipherInput;\r\n let initiatorContactCardSharedCipherInput;\r\n if (initiatorRootKeyCipherClearJson.initiatorContactCard) {\r\n // The initiatorContactCard created during the creation of the invite and encrypted using the initiator's\r\n // root key\r\n const initiatorContactCardFromInit =\r\n initiatorRootKeyCipherClearJson.initiatorContactCard;\r\n const ownerKey = await this.keyFactory.createKey();\r\n const sharedCipherKey = await KeyFactoryService.asKey(\r\n plainInitiatorOneTimePbkCipher.responder.contactCard.sharedCipherKey\r\n );\r\n\r\n const ownerWrappedKey = JSON.stringify(\r\n await this.encryptionService.encrypt(rootKey.jwk, ownerKey.toJSON(true))\r\n );\r\n\r\n // Allow the initiatorContactCard parameter to override\r\n const ownerCipherDataClearJson =\r\n initiatorContactCard?.ownerCipherDataClearJson ||\r\n initiatorContactCardFromInit.ownerCipherDataClearJson;\r\n\r\n const ownerCipherData = ownerCipherDataClearJson\r\n ? await this.keyGraph.encryptToString(\r\n ownerKey,\r\n ownerCipherDataClearJson\r\n )\r\n : '';\r\n\r\n initiatorContactCardCipherInput = {\r\n ownerWrappedKey,\r\n ownerWrappingKeyId: rootKey.id,\r\n ownerCipherData,\r\n };\r\n\r\n initiatorContactCardSharedCipherInput = {\r\n sigPxkId: initiatorSigPrk.id,\r\n };\r\n\r\n const sharedCipherData = await this.encryptionService.encrypt(\r\n sharedCipherKey,\r\n initiatorContactCardFromInit.sharedCipherDataClearJson\r\n );\r\n initiatorContactCardSharedCipherInput.sharedCipherDataSig = JSON.stringify(\r\n await this.encryptionService.sign(initiatorSigPrk.jwk, sharedCipherData)\r\n );\r\n }\r\n\r\n // TODO ideally we update the shared data in the contact card sent to the responder as well since that\r\n // CC was created by the responder.\r\n\r\n return new LrMutation({\r\n mutation: CompleteKeyExchangeOtkMutation,\r\n variables: {\r\n input: {\r\n keyExchangeId,\r\n rootKeyId: rootKey.id,\r\n masterKeyId: masterKey.id,\r\n initiatorSigPxkId: initiatorSigPrk.id,\r\n signedResponderPbk: JSON.stringify(signedResponderPbk),\r\n signedResponderSigPbk: JSON.stringify(signedResponderSigPbk),\r\n rkWrappedSharedKey: JSON.stringify(rkWrappedSharedKey),\r\n mkWrappedMkSharedKey: JSON.stringify(mkWrappedMkSharedKey),\r\n responderContactCardCipher: responderContactCardCipherInput,\r\n initiatorContactCardCipher: initiatorContactCardCipherInput,\r\n initiatorContactCardSharedCipher: initiatorContactCardSharedCipherInput,\r\n },\r\n },\r\n });\r\n }\r\n}\r\n","import { gqlTyped } from '../_common/ast';\r\nimport { ID } from './types';\r\n\r\nexport interface UpdateOwnedContactCardMutation {\r\n updateOwnedContactCard: {\r\n ownedContactCard: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const UpdateOwnedContactCardMutation = gqlTyped<UpdateOwnedContactCardMutation>`\r\nmutation UpdateOwnedContactCardMutation(\r\n $input: UpdateOwnedContactCardInput!\r\n) {\r\n updateOwnedContactCard(input: $input) {\r\n ownedContactCard {\r\n id\r\n }\r\n }\r\n}`;\r\n\r\nexport interface UpdateReceivedContactCardMutation {\r\n updateReceivedContactCard: {\r\n receivedContactCard: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const UpdateReceivedContactCardMutation = gqlTyped<UpdateReceivedContactCardMutation>`\r\nmutation UpdateReceivedContactCardMutation(\r\n $input: UpdateReceivedContactCardInput!\r\n) {\r\n updateReceivedContactCard(input: $input) {\r\n receivedContactCard {\r\n id\r\n }\r\n }\r\n}`;\r\n\r\nexport interface GetOwnedContactCardKeyIdsQuery {\r\n ownedContactCard: {\r\n sharedKey: {\r\n id: ID;\r\n };\r\n ownerKey: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const GetOwnedContactCardKeyIdsQuery = gqlTyped<GetOwnedContactCardKeyIdsQuery>`\r\nquery GetOwnedContactCardKeyIdsQuery($id: LrRelayIdInput!) {\r\n ownedContactCard(id: $id) {\r\n sharedKey {\r\n id\r\n }\r\n ownerKey {\r\n id\r\n }\r\n }\r\n}`;\r\n\r\nexport interface GetReceivedContactCardKeyIdQuery {\r\n receivedContactCard: {\r\n receiverKey: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const GetReceivedContactCardKeyIdQuery = gqlTyped<GetReceivedContactCardKeyIdQuery>`\r\nquery GetReceivedContactCardKeyIdQuery($id: LrRelayIdInput!) {\r\n receivedContactCard(id: $id) {\r\n receiverKey {\r\n id\r\n }\r\n }\r\n}`;\r\n","import { Injectable, NgZone } from '@angular/core';\r\nimport { Key } from '../cryptography/cryptography.types';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport { RunOutsideAngular } from '../_common/run-outside-angular';\r\nimport {\r\n ContactCardReceiverCipherData,\r\n SendContactCardInput,\r\n} from './key-exchange2.service';\r\nimport { LrGraphQLService, LrMutation } from './lr-graphql';\r\nimport {\r\n GetOwnedContactCardKeyIdsQuery,\r\n GetReceivedContactCardKeyIdQuery,\r\n UpdateOwnedContactCardMutation,\r\n UpdateReceivedContactCardMutation,\r\n} from './shared-contact-card2.gql';\r\nimport { LrRelayIdInput } from './types';\r\n\r\nexport interface UpdateOwnedContactCardInput extends SendContactCardInput {\r\n id: LrRelayIdInput;\r\n ownerKeyId?: LrRelayIdInput;\r\n sharedKeyId?: LrRelayIdInput;\r\n}\r\n\r\nexport interface UpdateReceivedContactCardInput\r\n extends ContactCardReceiverCipherData {\r\n id: LrRelayIdInput;\r\n receiverKeyId?: LrRelayIdInput;\r\n}\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class SharedContactCard2Service {\r\n constructor(\r\n private ngZone: NgZone,\r\n private keyService: KeyService,\r\n private keyGraph: KeyGraphService,\r\n private encryptionService: EncryptionService,\r\n private lrGraphQL: LrGraphQLService\r\n ) {}\r\n\r\n private async getOwnedContactCardKeyIds(id: LrRelayIdInput) {\r\n const { ownedContactCard: cc } = await this.lrGraphQL.query({\r\n query: GetOwnedContactCardKeyIdsQuery,\r\n variables: {\r\n id,\r\n },\r\n });\r\n\r\n return {\r\n sharedKeyId: cc.sharedKey.id,\r\n ownerKeyId: cc.ownerKey.id,\r\n };\r\n }\r\n\r\n private async getReceivedContactCardKeyId(id: LrRelayIdInput) {\r\n return (\r\n await this.lrGraphQL.query({\r\n query: GetReceivedContactCardKeyIdQuery,\r\n variables: {\r\n id,\r\n },\r\n })\r\n ).receivedContactCard.receiverKey.id;\r\n }\r\n\r\n async updateOwnedContactCard({\r\n id,\r\n ownerKeyId,\r\n sharedKeyId,\r\n ownerPlainDataJson,\r\n ownerCipherDataClearJson,\r\n sharedCipherDataClearJson,\r\n }: UpdateOwnedContactCardInput) {\r\n let ownerKey: Key;\r\n let sharedKey: Key;\r\n\r\n try {\r\n ownerKey = await this.keyGraph.getKey(ownerKeyId);\r\n sharedKey = await this.keyGraph.getKey(sharedKeyId);\r\n } catch (error) {\r\n const keys = await this.getOwnedContactCardKeyIds(id);\r\n\r\n // try again\r\n ownerKey = await this.keyGraph.getKey(keys.ownerKeyId);\r\n sharedKey = await this.keyGraph.getKey(keys.sharedKeyId);\r\n }\r\n\r\n const sigPxk = await this.keyService.getCurrentSigPxk();\r\n\r\n const sharedCipherData = await this.encryptionService.encrypt(\r\n sharedKey.jwk,\r\n sharedCipherDataClearJson\r\n );\r\n const sharedCipherDataSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, sharedCipherData)\r\n );\r\n\r\n const ownerPlainDataSig = JSON.stringify(\r\n await this.encryptionService.sign(sigPxk.jwk, ownerPlainDataJson)\r\n );\r\n\r\n const ownerCipherData = await this.encryptionService.encryptToString(\r\n ownerKey.jwk,\r\n ownerCipherDataClearJson\r\n );\r\n\r\n return new LrMutation({\r\n mutation: UpdateOwnedContactCardMutation,\r\n variables: {\r\n input: {\r\n id,\r\n ownerCipherData,\r\n ownerKeyId: ownerKey.id,\r\n sharedCipherDataSig,\r\n sharedKeyId: sharedKey.id,\r\n sigPxkId: sigPxk.id,\r\n ownerPlainDataSig,\r\n },\r\n },\r\n });\r\n }\r\n\r\n async updateReceivedContactCard({\r\n id,\r\n receiverKeyId,\r\n receiverCipherDataClearJson,\r\n }: UpdateReceivedContactCardInput) {\r\n const receiverKey = await this.keyGraph.getKey(receiverKeyId, () =>\r\n this.getReceivedContactCardKeyId(id)\r\n );\r\n\r\n const receiverCipherData = await this.encryptionService.encryptToString(\r\n receiverKey.jwk,\r\n receiverCipherDataClearJson\r\n );\r\n\r\n return new LrMutation({\r\n mutation: UpdateReceivedContactCardMutation,\r\n variables: {\r\n input: {\r\n id,\r\n receiverCipherData,\r\n receiverKeyId: receiverKey.id,\r\n },\r\n },\r\n });\r\n }\r\n}\r\n","import { JWK } from 'node-jose';\r\nimport { gqlTyped } from '../_common/ast';\r\nimport { DateTime, LockState, UUID } from './types';\r\n\r\nexport interface LockFragmentResult {\r\n created: DateTime;\r\n modified: DateTime;\r\n version?: UUID;\r\n expiryTime: DateTime;\r\n state: LockState;\r\n}\r\nexport const LockFragment = gqlTyped<LockFragmentResult>`\r\nfragment LockFragment on LockField {\r\n created\r\n modified\r\n version\r\n expiryTime\r\n state\r\n}`;\r\n\r\nexport interface UpdateLockMutationResult {\r\n updateLock: {\r\n lock: LockFragmentResult;\r\n };\r\n}\r\nexport const UpdateLockMutation = gqlTyped<UpdateLockMutationResult>`\r\nmutation UpdateLockMutation($input: UpdateLockInput!) {\r\n updateLock(input: $input) {\r\n lock {\r\n ...LockFragment\r\n }\r\n }\r\n}\r\n${LockFragment}\r\n`;\r\n\r\nexport interface AcquireLockMutationResult {\r\n acquireLock: {\r\n lock: LockFragmentResult;\r\n };\r\n}\r\nexport const AcquireLockMutation = gqlTyped<AcquireLockMutationResult>`\r\nmutation AcquireLockMutation($input: AcquireLockInput!) {\r\n acquireLock(input: $input) {\r\n lock {\r\n ...LockFragment\r\n }\r\n }\r\n}\r\n${LockFragment}\r\n`;\r\n\r\nexport interface ReleaseLockMutationResult {\r\n releaseLock: {\r\n lock: LockFragmentResult;\r\n };\r\n}\r\nexport const ReleaseLockMutation = gqlTyped<ReleaseLockMutationResult>`\r\nmutation ReleaseLockMutation($input: ReleaseLockInput!) {\r\n releaseLock(input: $input) {\r\n lock {\r\n ...LockFragment\r\n }\r\n }\r\n}\r\n${LockFragment}\r\n`;\r\n","import { Injectable, Injector, NgZone } from '@angular/core';\r\nimport { LrMutation, LrService } from './lr-graphql';\r\nimport {\r\n AcquireLockMutation,\r\n ReleaseLockMutation,\r\n UpdateLockMutation,\r\n} from './lock.gql';\r\nimport { RunOutsideAngular } from '../_common/run-outside-angular';\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class LockService extends LrService {\r\n constructor(private ngZone: NgZone, private injector: Injector) {\r\n super(injector);\r\n }\r\n\r\n // Updating the lock version is always to be down along with another mutation.\r\n updateLockMutation(resourceId: string, version: string) {\r\n return new LrMutation({\r\n mutation: UpdateLockMutation,\r\n variables: {\r\n input: {\r\n resourceId,\r\n version,\r\n },\r\n },\r\n });\r\n }\r\n\r\n acquireLockMutation(resourceId: string, timeoutMs: number) {\r\n return new LrMutation({\r\n mutation: AcquireLockMutation,\r\n variables: {\r\n input: {\r\n resourceId,\r\n timeoutMs,\r\n },\r\n },\r\n });\r\n }\r\n\r\n releaseLockMutation(resourceId: string, version: string) {\r\n return new LrMutation({\r\n mutation: ReleaseLockMutation,\r\n variables: {\r\n input: {\r\n resourceId,\r\n version,\r\n },\r\n },\r\n });\r\n }\r\n}\r\n","import { gqlTyped } from '../_common/ast';\r\nimport { ID } from '../api/types';\r\n\r\nexport interface DeleteTpMutation {\r\n deleteTp: {\r\n id: ID;\r\n };\r\n}\r\nexport const DeleteTpMutation = gqlTyped<DeleteTpMutation>`\r\nmutation DeleteTpMutation($input: DeleteTpInput!) {\r\n deleteTp(input: $input) {\r\n id\r\n }\r\n}\r\n`;\r\n\r\nexport interface ShareDirectoryMutation {\r\n shareDirectory: {\r\n tpDirectory: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const ShareDirectoryMutation = gqlTyped<ShareDirectoryMutation>`\r\n mutation ShareDirectoryMutation($input: ShareDirectoryInput!) {\r\n shareDirectory(input: $input) {\r\n tpDirectory {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport interface UnshareDirectoryMutation {\r\n unshareDirectory: {\r\n tpDirectory: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const UnshareDirectoryMutation = gqlTyped<UnshareDirectoryMutation>`\r\n mutation UnshareDirectoryMutation($input: UnshareDirectoryInput!) {\r\n unshareDirectory(input: $input) {\r\n tpDirectory {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport interface ShareFileMutation {\r\n shareFile: {\r\n tpFile: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const ShareFileMutation = gqlTyped<ShareFileMutation>`\r\n mutation ShareFileMutation($input: ShareFileInput!) {\r\n shareFile(input: $input) {\r\n tpFile {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport interface UnshareFileMutation {\r\n unshareFile: {\r\n tpFile: {\r\n id: ID;\r\n };\r\n };\r\n}\r\nexport const UnshareFileMutation = gqlTyped<UnshareFileMutation>`\r\n mutation UnshareFileMutation($input: UnshareFileInput!) {\r\n unshareFile(input: $input) {\r\n tpFile {\r\n id\r\n }\r\n }\r\n }\r\n`;\r\n\r\nexport interface TpCurrentUserSharedKeyQuery {\r\n tp: {\r\n currentUserSharedKey: {\r\n userSharedKey: {\r\n sharedKey: {\r\n id: ID;\r\n };\r\n mkSharedKey: {\r\n id: ID;\r\n };\r\n mkPxk: {\r\n id: ID;\r\n };\r\n mkReshareRequestCipher: string;\r\n mkReshareRequestSent: boolean;\r\n mkReshareResponseCipher: string;\r\n mkReshareResponseSent: boolean;\r\n };\r\n };\r\n };\r\n}\r\nexport const TpCurrentUserSharedKeyQuery = gqlTyped<TpCurrentUserSharedKeyQuery>`\r\nquery TpCurrentUserSharedKeyQuery($id: LrRelayIdInput!) {\r\n tp(id: $id){\r\n currentUserSharedKey {\r\n userSharedKey {\r\n sharedKey {\r\n id\r\n }\r\n mkSharedKey {\r\n id\r\n }\r\n mkPxk {\r\n id\r\n }\r\n mkReshareRequestCipher\r\n mkReshareRequestSent\r\n mkReshareResponseCipher\r\n mkReshareResponseSent\r\n }\r\n }\r\n }\r\n}\r\n`;\r\n\r\nexport interface RequestTpMkReshareMutation {\r\n requestTpMkReshare: {\r\n id: ID;\r\n };\r\n}\r\nexport const RequestTpMkReshareMutation = gqlTyped<RequestTpMkReshareMutation>`\r\nmutation RequestTpMkReshareMutation($input: RequestTpMkReshareInput!) {\r\n requestTpMkReshare(input: $input) {\r\n id\r\n }\r\n}`;\r\n\r\nexport interface RespondTpMkReshareMutation {\r\n respondTpMkReshare: {\r\n id: ID;\r\n };\r\n}\r\nexport const RespondTpMkReshareMutation = gqlTyped<RespondTpMkReshareMutation>`\r\n mutation RespondTpMkReshareMutation($input: RespondTpMkReshareInput!) {\r\n respondTpMkReshare(input: $input) {\r\n id\r\n }\r\n }\r\n`;\r\n\r\nexport interface CompleteTpMkReshareMutation {\r\n completeTpMkReshare: {\r\n id: ID;\r\n };\r\n}\r\nexport const CompleteTpMkReshareMutation = gqlTyped<CompleteTpMkReshareMutation>`\r\nmutation CompleteTpMkReshareMutation($input: CompleteTpMkReshareInput!) {\r\n completeTpMkReshare(input: $input) {\r\n id\r\n }\r\n}`;\r\n","import { Injectable, NgZone } from '@angular/core';\r\nimport { min } from 'moment';\r\nimport { JWK } from 'node-jose';\r\nimport { Item2Service } from '../api/item2.service';\r\nimport { LrGraphQLService, LrMutation } from '../api/lr-graphql';\r\nimport { AccessRoleChoice, LrRelayIdInput } from '../api/types';\r\nimport { Key } from '../cryptography/cryptography.types';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { KeyFactoryService } from '../cryptography/key-factory.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport { LrBadStateException } from '../_common/exceptions';\r\nimport { RunOutsideAngular } from '../_common/run-outside-angular';\r\nimport {\r\n CompleteTpMkReshareMutation,\r\n DeleteTpMutation,\r\n RequestTpMkReshareMutation,\r\n RespondTpMkReshareMutation,\r\n ShareDirectoryMutation,\r\n ShareFileMutation,\r\n TpCurrentUserSharedKeyQuery,\r\n UnshareDirectoryMutation,\r\n UnshareFileMutation,\r\n} from './trusted-party2.gql';\r\n\r\n// If xxxKeyId not given, then fetch them with API calls\r\nexport interface ShareItemOptions {\r\n itemId: LrRelayIdInput;\r\n itemKeyId?: LrRelayIdInput;\r\n tpId: LrRelayIdInput;\r\n tpSharedKeyId?: LrRelayIdInput;\r\n accessRole: AccessRoleChoice;\r\n}\r\n\r\nexport interface UnshareItemOptions {\r\n itemId: string;\r\n tpId: string;\r\n}\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class TrustedParty2Service {\r\n constructor(\r\n private ngZone: NgZone,\r\n private keyGraph: KeyGraphService,\r\n private lrGraphQL: LrGraphQLService,\r\n private item2Service: Item2Service,\r\n private keyService: KeyService,\r\n private keyFactory: KeyFactoryService,\r\n private encryptionService: EncryptionService\r\n ) {}\r\n\r\n // TODO: deprecate this\r\n public deleteTp(tpId: LrRelayIdInput) {\r\n return this.deleteTpMutation(tpId);\r\n }\r\n\r\n public deleteTpMutation(tpId: LrRelayIdInput) {\r\n return new LrMutation({\r\n mutation: DeleteTpMutation,\r\n variables: {\r\n input: {\r\n id: tpId,\r\n },\r\n },\r\n });\r\n }\r\n\r\n async getTpCurrentUserSharedKey(tpId: LrRelayIdInput) {\r\n return (\r\n await this.lrGraphQL.query({\r\n query: TpCurrentUserSharedKeyQuery,\r\n variables: {\r\n id: tpId,\r\n },\r\n })\r\n ).tp.currentUserSharedKey.userSharedKey;\r\n }\r\n\r\n async shareDirectory(options: ShareItemOptions) {\r\n return this.shareItem({ ...options, isDirectory: true });\r\n }\r\n\r\n async shareFile(options: ShareItemOptions) {\r\n return this.shareItem({ ...options, isDirectory: false });\r\n }\r\n\r\n private async shareItem({\r\n itemId,\r\n itemKeyId,\r\n tpId,\r\n tpSharedKeyId,\r\n accessRole,\r\n isDirectory,\r\n }: ShareItemOptions & {\r\n isDirectory: boolean;\r\n }) {\r\n const itemKey = await this.keyGraph.getKey(itemKeyId, () =>\r\n isDirectory\r\n ? this.item2Service.getDirectoryKeyId(itemId)\r\n : this.item2Service.getFileKeyId(itemId)\r\n );\r\n const wrappingKey = await this.keyGraph.getKey(tpSharedKeyId, () =>\r\n this.getTpCurrentUserSharedKey(tpId).then((res) => res.sharedKey.id)\r\n );\r\n const wrappedKey = await this.keyGraph.wrapKey(wrappingKey, itemKey.jwk);\r\n\r\n return new LrMutation({\r\n mutation: isDirectory ? ShareDirectoryMutation : ShareFileMutation,\r\n variables: {\r\n input: {\r\n id: itemId,\r\n tpId,\r\n accessRole,\r\n keyId: itemKey.id,\r\n wrappingKeyId: wrappingKey.id,\r\n wrappedKey,\r\n },\r\n },\r\n });\r\n }\r\n\r\n async unshareDirectory(options: UnshareItemOptions) {\r\n return this.unshareItem({ ...options, isDirectory: true });\r\n }\r\n\r\n async unshareFile(options: UnshareItemOptions) {\r\n return this.unshareItem({ ...options, isDirectory: false });\r\n }\r\n\r\n private async unshareItem({\r\n itemId,\r\n tpId,\r\n isDirectory,\r\n }: UnshareItemOptions & { isDirectory: boolean }) {\r\n return new LrMutation({\r\n mutation: isDirectory ? UnshareDirectoryMutation : UnshareFileMutation,\r\n variables: {\r\n input: {\r\n id: itemId,\r\n tpId,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async requestMkReshare(tpId: LrRelayIdInput) {\r\n const userSharedKey = await this.getTpCurrentUserSharedKey(tpId);\r\n\r\n if (userSharedKey.mkSharedKey) {\r\n throw new LrBadStateException('TP already has mkSharedKey');\r\n }\r\n\r\n const masterKey = await this.keyService.getCurrentMasterKey();\r\n const prk = await this.keyFactory.createPkcKey();\r\n const mkWrappedMkPrk = await this.encryptionService.encryptToString(\r\n masterKey.jwk,\r\n prk.toJSON(true)\r\n );\r\n\r\n const sharedKey = await this.keyGraph.getKey(userSharedKey.sharedKey.id);\r\n const mkReshareRequestCipher = await this.encryptionService.encryptToString(\r\n sharedKey.jwk,\r\n {\r\n pbk: prk.toJSON(),\r\n }\r\n );\r\n\r\n return await new LrMutation({\r\n mutation: RequestTpMkReshareMutation,\r\n variables: {\r\n input: {\r\n tpId,\r\n masterKeyId: masterKey.id,\r\n mkPbk: JSON.stringify(prk.toJSON()),\r\n mkWrappedMkPrk,\r\n sharedKeyId: sharedKey.id,\r\n mkReshareRequestCipher,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async respondMkReshare(tpId: LrRelayIdInput) {\r\n const userSharedKey = await this.getTpCurrentUserSharedKey(tpId);\r\n\r\n if (!userSharedKey.mkSharedKey) {\r\n throw new LrBadStateException(\r\n 'No access to the mkSharedKey so cannot reshare it with TP'\r\n );\r\n }\r\n\r\n const sharedKey = await this.keyGraph.getKey(userSharedKey.sharedKey.id);\r\n const plainMkReshareRequestCipher = await this.encryptionService.decrypt(\r\n sharedKey,\r\n userSharedKey.mkReshareRequestCipher\r\n );\r\n const pbk = await JWK.asKey(plainMkReshareRequestCipher.pbk);\r\n const mkSharedKey = await this.keyGraph.getKey(\r\n userSharedKey.mkSharedKey.id\r\n );\r\n\r\n const plainMkReshareResponseCipher = {\r\n mkSharedKey: {\r\n id: mkSharedKey.id,\r\n jwk: mkSharedKey.jwk.toJSON(true),\r\n },\r\n };\r\n\r\n // Wrap with sharedKey then again with Pbk\r\n const mkReshareResponseCipher = await this.encryptionService.encryptToString(\r\n pbk,\r\n await this.encryptionService.encryptToString(\r\n sharedKey.jwk,\r\n plainMkReshareResponseCipher\r\n )\r\n );\r\n\r\n return new LrMutation({\r\n mutation: RespondTpMkReshareMutation,\r\n variables: {\r\n input: {\r\n tpId,\r\n mkSharedKeyId: mkSharedKey.id,\r\n mkReshareResponseCipher,\r\n },\r\n },\r\n });\r\n }\r\n\r\n public async completeMkReshare(tpId: LrRelayIdInput) {\r\n const userSharedKey = await this.getTpCurrentUserSharedKey(tpId);\r\n\r\n const sharedKey = await this.keyGraph.getKey(userSharedKey.sharedKey.id);\r\n const prk = await this.keyGraph.getKey(userSharedKey.mkPxk.id);\r\n const plainMkReshareResponseCipher = await this.encryptionService.decrypt(\r\n sharedKey,\r\n await this.encryptionService.decrypt(\r\n prk,\r\n userSharedKey.mkReshareResponseCipher\r\n )\r\n );\r\n\r\n // Double check it's a valid key.\r\n const mkSharedKey: Key = {\r\n id: plainMkReshareResponseCipher.mkSharedKey.id,\r\n jwk: await JWK.asKey(plainMkReshareResponseCipher.mkSharedKey.jwk),\r\n };\r\n\r\n const masterKey = await this.keyService.getCurrentMasterKey();\r\n const mkWrappedMkSharedKey = await this.encryptionService.encryptToString(\r\n masterKey.jwk,\r\n mkSharedKey.jwk.toJSON(true)\r\n );\r\n\r\n return new LrMutation({\r\n mutation: CompleteTpMkReshareMutation,\r\n variables: {\r\n input: {\r\n tpId,\r\n masterKeyId: masterKey.id,\r\n mkSharedKeyId: mkSharedKey.id,\r\n mkWrappedMkSharedKey,\r\n },\r\n },\r\n });\r\n }\r\n}\r\n","import { Injectable, Injector, NgZone } from '@angular/core';\r\nimport { KeyService } from '../cryptography/key.service';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport {\r\n CreateTpPasswordResetMutation,\r\n DeleteTpPasswordResetMutation,\r\n TpPasswordResetQuery,\r\n UpdateTpPasswordResetMutation,\r\n CancelTpPasswordResetRequestMutation,\r\n} from './tp-password-reset.gql';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport * as slip from '../cryptography/slip39.service';\r\nimport {\r\n LrBadArgumentException,\r\n LrBadLogicException,\r\n} from '../_common/exceptions';\r\nimport { PartialAssemblyKey } from '../scenario/scenario.types';\r\nimport { JWK } from 'node-jose';\r\nimport { Key } from '../cryptography/cryptography.types';\r\nimport { KeyFactoryService } from '../cryptography/key-factory.service';\r\nimport { LrGraphQLService, LrMutation, LrService } from '../api/lr-graphql';\r\nimport { TpNode } from '../api/types';\r\nimport { RunOutsideAngular } from '../_common/run-outside-angular';\r\n\r\nexport class CreateSubAssembliesInput {\r\n name: string;\r\n quorum: number;\r\n singleReject: boolean;\r\n approverTps: TpNode[];\r\n}\r\n\r\nexport class UpdateSubAssembliesInput extends CreateSubAssembliesInput {\r\n id: string;\r\n}\r\n\r\nexport class CreateTpPasswordResetInput {\r\n quorum: number;\r\n singleReject: boolean;\r\n createSubAssemblies: CreateSubAssembliesInput[];\r\n}\r\n\r\nexport class UpdateTpPasswordResetInput extends CreateTpPasswordResetInput {\r\n updateSubAssemblies: UpdateSubAssembliesInput[];\r\n}\r\n\r\nexport interface TpAssemblyApprovers {\r\n id: string;\r\n tp: {\r\n id: string;\r\n };\r\n sharedKey: Key;\r\n sharedCipherData?: string;\r\n sharedCipherDataClearJson?: any;\r\n sharedCipherApprovalData?: string;\r\n sharedCipherApprovalDataClearJson?: any;\r\n}\r\n\r\nexport interface TpSubAssembly {\r\n id: string;\r\n singleReject: boolean;\r\n quorum: number;\r\n subjectCipherData: string;\r\n plainSubjectCipherData: any;\r\n approvers: TpAssemblyApprovers[];\r\n}\r\n\r\nexport interface TpAssembly {\r\n singleReject: boolean;\r\n quorum: number;\r\n subjectKey: Key;\r\n assemblyKey: Key;\r\n assemblyCipherData: string;\r\n plainAssemblyCipherData: any;\r\n subAssemblies: TpSubAssembly[];\r\n}\r\n\r\nexport interface TpPasswordReset {\r\n id: string;\r\n assembly: TpAssembly;\r\n applied: boolean;\r\n}\r\n\r\nexport interface RequestResetResult {\r\n id: string;\r\n associate_reset_user_token: string;\r\n reset_username: string;\r\n}\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class TpPasswordResetService extends LrService {\r\n public static SLIP39_PASSPHRASE = 'lifeready';\r\n\r\n constructor(\r\n private ngZone: NgZone,\r\n private injector: Injector,\r\n private keyService: KeyService,\r\n private keyFactory: KeyFactoryService,\r\n private encryptionService: EncryptionService,\r\n private keyGraph: KeyGraphService,\r\n private slip39Service: slip.Slip39Service\r\n ) {\r\n super(injector);\r\n }\r\n\r\n async getReset() {\r\n return (\r\n await this.query({\r\n query: TpPasswordResetQuery,\r\n })\r\n ).tpPasswordReset;\r\n }\r\n\r\n createReset(input: CreateTpPasswordResetInput) {\r\n return this.mutate(this.createResetMutation(input));\r\n }\r\n\r\n async createResetMutation(input: CreateTpPasswordResetInput) {\r\n const { mutationInput } = await this._createReset(\r\n input,\r\n async (rawAssemblyKey) => {\r\n return this.prepareSlip39(\r\n input.createSubAssemblies,\r\n input.quorum,\r\n rawAssemblyKey\r\n );\r\n }\r\n );\r\n\r\n return new LrMutation({\r\n mutation: CreateTpPasswordResetMutation,\r\n variables: {\r\n input: mutationInput,\r\n },\r\n });\r\n }\r\n\r\n deleteReset() {\r\n return this.mutate(this.deleteResetMutation());\r\n }\r\n\r\n deleteResetMutation() {\r\n return new LrMutation({\r\n mutation: DeleteTpPasswordResetMutation,\r\n });\r\n }\r\n\r\n updateReset(input: UpdateTpPasswordResetInput) {\r\n return this.mutate(this.updateResetMutation(input));\r\n }\r\n\r\n async updateResetMutation(input: UpdateTpPasswordResetInput) {\r\n const passwordReset = await this.getReset();\r\n\r\n const {\r\n mutationInput,\r\n subjectKey,\r\n slipAssembly,\r\n assemblyKeyParams,\r\n } = await this._createReset(input, async (rawAssemblyKey) => {\r\n return this.prepareSlip39(\r\n input.createSubAssemblies.concat(input.updateSubAssemblies),\r\n input.quorum,\r\n rawAssemblyKey\r\n );\r\n });\r\n\r\n const updateSubAssemblies = await Promise.all(\r\n input.updateSubAssemblies.map(async (sa, saIndex) => {\r\n const subjectCipherData = await this.encryptionService.encryptToString(\r\n subjectKey,\r\n {\r\n name: sa.name,\r\n }\r\n );\r\n\r\n // Get the existing sub-assembly\r\n const existingSa = passwordReset.assembly.subAssemblies.edges.find(\r\n (edge) => edge.node.id === sa.id\r\n ).node;\r\n\r\n // Get approvers that do not exist yet\r\n const createApprovers = [];\r\n const updateApprovers = [];\r\n\r\n sa.approverTps.forEach((tp) => {\r\n const approver = existingSa.approvers.edges.find(\r\n (edge) => edge.node.tp.id === tp.id\r\n )?.node;\r\n if (approver) {\r\n updateApprovers.push({\r\n tp,\r\n approverId: approver.id,\r\n });\r\n } else {\r\n createApprovers.push({\r\n tp,\r\n });\r\n }\r\n });\r\n\r\n return {\r\n subAssemblyId: sa.id,\r\n singleReject: sa.singleReject,\r\n quorum: sa.quorum,\r\n subjectCipherData,\r\n createApprovers: await Promise.all(\r\n createApprovers.map(async ({ tp }, approverIndex) =>\r\n this.prepareApprover({\r\n tp,\r\n approverIndex,\r\n saIndex: saIndex + input.createSubAssemblies.length, // slipAssembly is all sub-assemblies combined\r\n slipAssembly,\r\n assemblyKeyParams,\r\n subjectKey,\r\n })\r\n )\r\n ),\r\n updateApprovers: await Promise.all(\r\n updateApprovers.map(async ({ tp, approverId }, approverIndex) =>\r\n this.prepareApprover({\r\n approverId,\r\n tp,\r\n approverIndex: approverIndex + createApprovers.length,\r\n saIndex: saIndex + input.createSubAssemblies.length, // slipAssembly is all sub-assemblies combined\r\n slipAssembly,\r\n assemblyKeyParams,\r\n subjectKey,\r\n })\r\n )\r\n ),\r\n };\r\n })\r\n );\r\n\r\n return new LrMutation({\r\n mutation: UpdateTpPasswordResetMutation,\r\n variables: {\r\n input: {\r\n ...mutationInput,\r\n assembly: {\r\n ...mutationInput.assembly,\r\n updateSubAssemblies,\r\n },\r\n },\r\n },\r\n });\r\n }\r\n\r\n cancelResetRequest() {\r\n return this.mutate(this.cancelResetRequestMutation());\r\n }\r\n\r\n cancelResetRequestMutation() {\r\n return new LrMutation({\r\n mutation: CancelTpPasswordResetRequestMutation,\r\n });\r\n }\r\n\r\n validateApprovers(approvers: TpNode[]): void {\r\n // Ensure all approvers have mkSharedKey.\r\n for (const tp of approvers) {\r\n if (!tp.currentUserSharedKey.userSharedKey.mkSharedKey) {\r\n const msg = `tp ${tp.other.username} does not have mkSharedKey`;\r\n console.log(msg);\r\n throw new LrBadArgumentException(msg);\r\n }\r\n }\r\n }\r\n\r\n private async prepareApprover({\r\n approverId,\r\n tp,\r\n approverIndex,\r\n saIndex,\r\n slipAssembly,\r\n assemblyKeyParams,\r\n subjectKey,\r\n }: {\r\n approverId?: string;\r\n tp: TpNode;\r\n approverIndex: number;\r\n saIndex: number;\r\n slipAssembly: slip.Assembly;\r\n assemblyKeyParams: object;\r\n subjectKey: JWK.Key;\r\n }) {\r\n if (!tp.currentUserSharedKey.userSharedKey.mkSharedKey) {\r\n throw new LrBadArgumentException(\r\n `Tp ${tp.other.username} does not have mkSharedKey. Need to reshared it first.`\r\n );\r\n }\r\n\r\n const sharedKey = await this.keyFactory.createKey();\r\n const tpMkSharedKey = await this.keyGraph.getKey(\r\n tp.currentUserSharedKey.userSharedKey.mkSharedKey.id\r\n );\r\n // For TP to access shared_key\r\n const tpMkSharedKeyWrappedSharedKey = await this.encryptionService.encryptToString(\r\n tpMkSharedKey.jwk,\r\n sharedKey.toJSON(true)\r\n );\r\n // For subject to access shared_key\r\n const subjectKeyWrappedSharedKey = await this.encryptionService.encryptToString(\r\n subjectKey,\r\n sharedKey.toJSON(true)\r\n );\r\n\r\n const saSlip = slipAssembly.subAssemblies[saIndex];\r\n if (saSlip.index !== saIndex) {\r\n // Paranoia\r\n throw new LrBadLogicException(\r\n 'slip sub assembly index should match with array index'\r\n );\r\n }\r\n\r\n // If quorum is 1, then using the same share for every member.\r\n const share =\r\n saSlip.threshold === 1 ? saSlip.shares[0] : saSlip.shares[approverIndex];\r\n\r\n const partialAssemblyKey: PartialAssemblyKey = {\r\n slip39: {\r\n share,\r\n subAssembly: {\r\n quorum: saSlip.threshold,\r\n size: saSlip.size,\r\n },\r\n },\r\n assemblyKeyParams,\r\n };\r\n\r\n console.log('partialAssemblyKey', partialAssemblyKey);\r\n\r\n return {\r\n tpMkSharedKeyId: tpMkSharedKey.id,\r\n tpMkSharedKeyWrappedSharedKey,\r\n subjectKeyWrappedSharedKey,\r\n sharedCipherData: await this.encryptionService.encryptToString(\r\n sharedKey,\r\n { a: '123' }\r\n ),\r\n sharedCipherApprovalData: '',\r\n sharedCipherPartialAssemblyKey: await this.encryptionService.encryptToString(\r\n sharedKey,\r\n partialAssemblyKey\r\n ),\r\n approverId: approverId || void 0,\r\n tpId: approverId ? void 0 : tp.id,\r\n };\r\n }\r\n\r\n // Prepare slip39\r\n private async prepareSlip39(\r\n subAssemblies,\r\n assemblyQuorum: number,\r\n rawAssemblyKey: string\r\n ): Promise<slip.Assembly> {\r\n // Is there enough sub assemblies to meet quorum\r\n if (subAssemblies.length < assemblyQuorum) {\r\n throw new LrBadArgumentException(\r\n 'Not enough sub assemblies to meet quorum'\r\n );\r\n }\r\n\r\n const slipAssembly = new slip.Assembly(assemblyQuorum);\r\n\r\n subAssemblies.forEach((sa, index) => {\r\n let approverCount = sa.approverTps.length;\r\n\r\n // slip39 restricts quorum == 1 to have only 1 member. So we just share the same\r\n // partial key for all sub assembly members.\r\n if (sa.quorum === 1) {\r\n approverCount = 1;\r\n }\r\n slipAssembly.addSubAssembly(\r\n new slip.SubAssembly(index, sa.quorum, approverCount)\r\n );\r\n });\r\n\r\n await this.slip39Service.generateShares(\r\n rawAssemblyKey,\r\n TpPasswordResetService.SLIP39_PASSPHRASE,\r\n slipAssembly\r\n );\r\n return slipAssembly;\r\n }\r\n\r\n private async _createReset(\r\n input: CreateTpPasswordResetInput,\r\n createSlipAssembly\r\n ): Promise<any> {\r\n // Create subject key\r\n const masterKey = await this.keyService.getCurrentMasterKey();\r\n const subjectKey = await this.keyFactory.createKey();\r\n const assemblyKey = await this.keyFactory.createKey();\r\n const { k: rawAssemblyKey, ...assemblyKeyParams } = assemblyKey.toJSON(\r\n true\r\n ) as any;\r\n const assemblyKeyVerifierPrk = await this.keyFactory.createPkcSignKey();\r\n const wrappedAssemblyKeyVerifierPrk = await this.encryptionService.encryptToString(\r\n assemblyKey,\r\n assemblyKeyVerifierPrk.toJSON(true)\r\n );\r\n\r\n const masterKeyWrappedSubjectKey = await this.encryptionService.encryptToString(\r\n masterKey.jwk,\r\n subjectKey.toJSON(true)\r\n );\r\n const subjectKeyWrappedAssemblyKey = await this.encryptionService.encryptToString(\r\n subjectKey,\r\n assemblyKey.toJSON(true)\r\n );\r\n\r\n // Encrypt the rootKey with the assemblyKey\r\n const rootKey = await this.keyService.getCurrentRootKey();\r\n\r\n const assemblyCipherData = await this.encryptionService.encryptToString(\r\n assemblyKey,\r\n {\r\n rootKey: rootKey.jwk.toJSON(true),\r\n }\r\n );\r\n\r\n const slipAssembly = await createSlipAssembly(rawAssemblyKey);\r\n // const slipAssembly = await this.prepareSlip39(input.createSubAssemblies, input.quorum, rawAssemblyKey);\r\n\r\n const createSubAssemblies = await Promise.all(\r\n input.createSubAssemblies.map(async (sa, saIndex) => {\r\n const subjectCipherData = await this.encryptionService.encryptToString(\r\n subjectKey,\r\n {\r\n name: sa.name,\r\n }\r\n );\r\n\r\n return {\r\n singleReject: sa.singleReject,\r\n quorum: sa.quorum,\r\n subjectCipherData,\r\n createApprovers: await Promise.all(\r\n sa.approverTps.map(async (approverTp, approverIndex) =>\r\n this.prepareApprover({\r\n tp: approverTp,\r\n approverIndex,\r\n saIndex,\r\n slipAssembly,\r\n assemblyKeyParams,\r\n subjectKey,\r\n })\r\n )\r\n ),\r\n };\r\n })\r\n );\r\n\r\n return {\r\n subjectKey,\r\n slipAssembly,\r\n assemblyKeyParams,\r\n mutationInput: {\r\n assembly: {\r\n singleReject: input.singleReject,\r\n quorum: input.quorum,\r\n masterKeyId: masterKey.id,\r\n masterKeyWrappedSubjectKey,\r\n subjectKeyWrappedAssemblyKey,\r\n subjectCipherData: '',\r\n assemblyCipherData,\r\n createSubAssemblies,\r\n assemblyKeyVerifierPbk: JSON.stringify(\r\n assemblyKeyVerifierPrk.toJSON()\r\n ),\r\n wrappedAssemblyKeyVerifierPrk,\r\n },\r\n },\r\n };\r\n }\r\n}\r\n","// ------------------------------------------------------\r\n// Basic types\r\n// ------------------------------------------------------\r\n// These types map directory to types of the same name in graphql.\r\n// We use these aliases in case in the future we wish to reify the types and do\r\n// additional automated conversion.\r\n\r\nexport type ID = string;\r\n// Server requires this to have certain format. But client\r\n// just treats this as an opaque string.\r\nexport type LrRelayIdInput = string;\r\nexport type DateTime = string;\r\n// This is basically the results of: JSON.stringify(obj)\r\n// Server validated to make sure it can JSON.parse() this.\r\nexport type LrJSONString = string;\r\n// JSONString is a type from graphene. DB JSON fields maps to this type\r\n// automatically.\r\n// Where as LrJSONString is out custom implementation for input variables.\r\nexport type JSONString = string;\r\nexport type LrEmail = string;\r\nexport type GenericScalar = any;\r\nexport type UUID = string;\r\n\r\nexport interface Node {\r\n id?: string;\r\n}\r\n\r\nexport interface TimeStamped {\r\n created?: DateTime;\r\n modified?: DateTime;\r\n}\r\n\r\nexport interface Edge<NodeType extends Node> {\r\n node?: NodeType;\r\n cursor?: string;\r\n}\r\n\r\nexport interface Connection<NodeType> {\r\n pageInfo?: PageInfo;\r\n edges?: Edge<NodeType>[];\r\n}\r\n\r\nexport interface PageInfo {\r\n hasNextPage?: boolean;\r\n hasPreviousPage?: boolean;\r\n startCursor?: string;\r\n endCursor?: string;\r\n}\r\n","import { Time } from '@angular/common';\r\nimport {\r\n Connection,\r\n DateTime,\r\n GenericScalar,\r\n ID,\r\n JSONString,\r\n LrEmail,\r\n Node,\r\n TimeStamped,\r\n} from './graphql.types';\r\n\r\n// TODO: fill these types\r\nexport type UserStripeNode = any;\r\nexport type UserPlanNode = any;\r\nexport type UserDeleteNode = any;\r\nexport type FeaturesNode = any;\r\nexport type ScenarioNode = any;\r\nexport type SharedScenarioNode = any;\r\n\r\nexport type TpPasswordResetRequestNode = any;\r\n\r\nexport interface PassKeyNode extends Node, TimeStamped {\r\n passKeyParams?: GenericScalar;\r\n passIdpParams?: GenericScalar;\r\n wrappedPassIdpVerifierPrk?: GenericScalar;\r\n}\r\n\r\nexport interface CurrentUserKeyNode extends Node, TimeStamped {\r\n passKeys?: PassKeyNode[];\r\n passKey?: PassKeyNode;\r\n rootKey?: KeyNode;\r\n masterKey?: KeyNode;\r\n pxk?: KeyNode;\r\n sigPxk?: KeyNode;\r\n}\r\n\r\n// ------------------------------------------------------\r\n// Node types\r\n// ------------------------------------------------------\r\nexport interface UserNode extends Node {\r\n username?: string;\r\n contactCards?: Connection<ContactCardNode>;\r\n currentUserKey?: CurrentUserKeyNode;\r\n ownedContactCard?: SharedContactCardNode;\r\n receivedContactCard?: SharedContactCardNode;\r\n isCurrentUser?: boolean;\r\n haveTp?: boolean;\r\n stripe?: UserStripeNode;\r\n userPlans?: Connection<UserPlanNode>;\r\n userDelete?: UserDeleteNode;\r\n features?: FeaturesNode;\r\n}\r\n\r\nexport interface ServerTime {\r\n timestamp?: string;\r\n}\r\n\r\nexport interface KeyNode extends Node, TimeStamped {\r\n pbk?: string;\r\n}\r\n\r\nexport interface ContactCardNode extends Node, TimeStamped {\r\n owner?: UserNode;\r\n publicDataSig?: string;\r\n publicSearchableSig?: string;\r\n sigPxk?: KeyNode;\r\n defaultFrom?: DateTime;\r\n publicData?: string;\r\n publicSearchable?: string;\r\n cipherData?: string;\r\n cipherDataClearJson?: any;\r\n key?: KeyNode;\r\n plainData?: string;\r\n plainDataSig?: string;\r\n}\r\n\r\nexport interface DirectoryNode extends Node, TimeStamped {\r\n plainMeta?: JSONString;\r\n plainMetaJson?: any;\r\n cipherMeta?: string;\r\n cipherMetaClearJson?: any;\r\n archived?: boolean;\r\n keyId?: ID;\r\n childFileLinks?: Connection<FileLinkNode>;\r\n childDirectoryLinks?: Connection<DirectoryLinkNode>;\r\n parentDirectoryLinks?: Connection<DirectoryLinkNode>;\r\n nParentDirectoryLinks?: DirectoryLinkNodeLrNList;\r\n descendants?: Descendants;\r\n accessRoles?: AccessRole[];\r\n}\r\n\r\nexport interface FileNode extends Node, TimeStamped {\r\n currentVersion?: FileVersionNode;\r\n archived?: boolean;\r\n versions?: Connection<FileVersionNode>;\r\n keyId?: ID;\r\n parentDirectoryLinks?: Connection<FileLinkNode>;\r\n nParentDirectoryLinks?: FileLinkNodeLrNList;\r\n accessRoles?: AccessRole[];\r\n}\r\n\r\nexport interface DirectoryLinkNode extends Node, TimeStamped {\r\n parentDirectory?: DirectoryNode;\r\n childDirectory?: DirectoryNode;\r\n}\r\n\r\nexport interface FileLinkNode extends Node, TimeStamped {\r\n parentDirectory?: DirectoryNode;\r\n childFile?: FileNode;\r\n}\r\n\r\nexport interface DirectoryLinkNodeLrNList {\r\n list?: DirectoryLinkNode[];\r\n}\r\n\r\nexport interface FileLinkNodeLrNList {\r\n list?: FileLinkNode[];\r\n}\r\n\r\nexport interface Descendants {\r\n directories?: Connection<DirectoryNode>;\r\n files?: Connection<FileNode>;\r\n directoriesCount?: number;\r\n filesCount?: number;\r\n}\r\n\r\nexport enum AccessRoleChoice {\r\n READER = 'READER',\r\n WRITER = 'WRITER',\r\n ADMIN = 'ADMIN',\r\n DENY = 'DENY',\r\n OWNER = 'OWNER',\r\n}\r\n\r\nexport enum AccessRoleMethod {\r\n inherited = 'inherited',\r\n direct = 'direct',\r\n}\r\n\r\nexport interface AccessRole {\r\n issuer?: UserNode;\r\n subject?: UserNode;\r\n role?: AccessRoleChoice;\r\n method?: AccessRoleMethod;\r\n inheritedFrom?: DirectoryNode;\r\n trustedParty?: TpNode;\r\n isIssuer?: boolean;\r\n}\r\n\r\nexport enum FileVersionOperation {\r\n CREATE = 'CREATE',\r\n READ = 'READ',\r\n UPDATE = 'UPDATE',\r\n REVERT = 'REVERT',\r\n DELETE = 'DELETE',\r\n}\r\n\r\nexport interface FileVersionNode extends Node, TimeStamped {\r\n file?: FileNode;\r\n state?: FileStateNode;\r\n operation?: FileVersionOperation;\r\n author?: UserNode;\r\n}\r\nexport interface FileStateNode extends Node, TimeStamped {\r\n plainMeta?: JSONString;\r\n plainMetaJson?: any;\r\n cipherMeta?: string;\r\n cipherMetaClearJson?: any;\r\n contentResource?: string;\r\n versions?: Connection<FileVersionNode>;\r\n keyId: ID;\r\n}\r\n\r\nexport enum KeyExchangeOtkState {\r\n OTK_INITIATED = 'OTK_INITIATED',\r\n OTK_ACCEPTED = 'OTK_ACCEPTED',\r\n OTK_COMPLETED = 'OTK_COMPLETED',\r\n}\r\n\r\nexport interface ContactCardSharedCipherData {\r\n // Shared read access between initiator and responder. But only the initiator has write access.\r\n sharedCipherDataClearJson: any;\r\n}\r\n\r\n/**\r\n * The contents of the one-time key cipher\r\n */\r\nexport interface OtKeyCipherClearJson2 {\r\n // Used to confirm to the initiator that the responder has access to the one-time key.\r\n nonce: string;\r\n // Data sent from initiator to the responder\r\n initiator: {\r\n oneTimePbk: object; // one-time public encryption key the responder will use to send data back to the initiator\r\n pbk: object; // public encryption key\r\n sigPbk: object; // public signing key\r\n message?: any;\r\n contactCard?: ContactCardSharedCipherData;\r\n };\r\n}\r\n\r\nexport interface KeyExchangeOtkNode extends Node, TimeStamped {\r\n state?: KeyExchangeOtkState;\r\n sharedKey?: KeyNode;\r\n mkSharedKey?: KeyNode;\r\n initiatorSigPxk?: KeyNode;\r\n responderSigPxk?: KeyNode;\r\n initiatorOneTimePbkCipher?: string;\r\n otKeyParams?: string;\r\n otKeyCipher?: string;\r\n otKeyCipherClearJson?: OtKeyCipherClearJson2;\r\n responderPbkCipher?: string;\r\n}\r\n\r\nexport enum KeyExchangeState {\r\n IN_PROGRESS = 'IN_PROGRESS',\r\n COMPLETED = 'COMPLETED',\r\n DECLINED = 'DECLINED',\r\n CANCELLED = 'CANCELLED',\r\n DELETED = 'DELETED',\r\n}\r\n\r\nexport enum KeyExchangeMode {\r\n OTK = 'OTK',\r\n}\r\n\r\nexport interface KeyExchangeNode extends Node, TimeStamped {\r\n expiryTime?: DateTime;\r\n token?: string;\r\n tokenExpiryTime?: DateTime;\r\n state?: KeyExchangeState;\r\n mode?: KeyExchangeMode;\r\n initiator?: UserNode;\r\n responder?: UserNode;\r\n initiatorRootKeyCipher?: string;\r\n responderRootKeyCipher?: string;\r\n initiatorActionRequired?: boolean;\r\n responderActionRequired?: boolean;\r\n createTp?: boolean;\r\n otk?: KeyExchangeOtkNode;\r\n isInitiator?: boolean;\r\n isExpired?: boolean;\r\n responderEmailAddress?: LrEmail;\r\n}\r\n\r\nexport interface SharedItems {\r\n directories?: Connection<DirectoryNode>;\r\n files?: Connection<FileNode>;\r\n}\r\n\r\nexport interface SharedContactCardNode extends Node, TimeStamped {\r\n owner?: UserNode;\r\n receiver?: UserNode;\r\n sharedKey?: KeyNode;\r\n sharedCipherData?: string;\r\n sharedCipherDataClearJson?: any;\r\n sharedCipherDataSig?: string;\r\n sharedCipherDataSigPxk?: KeyNode;\r\n ownerCipherData?: string;\r\n ownerCipherDataClearJson?: any;\r\n ownerKey?: KeyNode;\r\n ownerPlainData?: string;\r\n ownerPlainDataJson?: any;\r\n ownerPlainDataSig?: string;\r\n receiverCipherData?: string;\r\n receiverCipherDataClearJson?: any;\r\n receiverKey?: KeyNode;\r\n}\r\n\r\nexport interface UserSharedKeyNode extends Node, TimeStamped {\r\n keyExchange?: KeyExchangeNode;\r\n user?: UserNode;\r\n userPrk?: KeyNode;\r\n userSigPrk?: KeyNode;\r\n other?: UserNode;\r\n otherPbk?: KeyNode;\r\n otherSigPbk?: KeyNode;\r\n sharedKey?: KeyNode;\r\n mkSharedKey?: KeyNode;\r\n mkPxk?: KeyNode;\r\n mkReshareRequestCipher?: string;\r\n mkReshareResponseCipher?: string;\r\n mkReshareRequestCipherClearJson?: any;\r\n mkReshareResponseCipherClearJson?: any;\r\n mkReshareRequestSent?: boolean;\r\n mkReshareResponseSent?: boolean;\r\n}\r\n\r\nexport interface CurrentUserSharedKeyNode extends Node, TimeStamped {\r\n user?: UserNode;\r\n other?: UserNode;\r\n userSharedKey?: UserSharedKeyNode;\r\n}\r\n\r\nexport interface TpNode extends Node, TimeStamped {\r\n user?: UserNode;\r\n other?: UserNode;\r\n currentUserSharedKey?: CurrentUserSharedKeyNode;\r\n isCompleted?: boolean;\r\n sharedKey?: KeyNode;\r\n sharedContactCard?: SharedContactCardNode;\r\n myContactCard?: SharedContactCardNode;\r\n myItems?: SharedItems;\r\n sharedItems?: SharedItems;\r\n myScenarios?: Connection<ScenarioNode>;\r\n sharedScenarios?: Connection<SharedScenarioNode>;\r\n}\r\n\r\nexport enum TpAssemblyState {\r\n DISABLED = 'DISABLED',\r\n ENABLED = 'ENABLED',\r\n CLAIMED = 'CLAIMED',\r\n APPROVED = 'APPROVED',\r\n REJECTED = 'REJECTED',\r\n EXPIRED = 'EXPIRED',\r\n CANCELLED = 'CANCELLED',\r\n RESET = 'RESET',\r\n}\r\n\r\nexport enum TpClaimState {\r\n CLAIMED = 'CLAIMED',\r\n APPROVED = 'APPROVED',\r\n REJECTED = 'REJECTED',\r\n EXPIRED = 'EXPIRED',\r\n CANCELLED = 'CANCELLED',\r\n RESET = 'RESET',\r\n}\r\n\r\nexport enum TpClaimApproverState {\r\n CLAIMED = 'CLAIMED',\r\n APPROVED = 'APPROVED',\r\n REJECTED = 'REJECTED',\r\n}\r\n\r\nexport interface TpPasswordResetApproval extends Node, TimeStamped {\r\n approverEmail?: string;\r\n receiverCipher?: string;\r\n receiverCipherClearJson?: any;\r\n receiverCipherPartialAssemblyKey?: string;\r\n receiverCipherPartialAssemblyKeyClearJson?: any;\r\n}\r\n\r\n// export interface TpPasswordResetUser {\r\n// username?: string;\r\n// resetUsername?: string;\r\n// state?: TpAssemblyState;\r\n// passKey?: PassKeyNode;\r\n// masterKey?: KeyNode;\r\n// pxk?: KeyNode;\r\n// approvals?: TpPasswordResetApproval[];\r\n// assemblyCipherData?: string;\r\n// wrappedAssemblyKeyVerifierPrk?: string;\r\n// }\r\n\r\nexport interface TpPasswordResetUserApprovalNode extends Node, TimeStamped {\r\n receiverCipher?: string;\r\n receiverCipherClearJson?: any;\r\n receiverCipherPartialAssemblyKey?: string;\r\n receiverCipherPartialAssemblyKeyClearJson?: any;\r\n approverEmail?: string;\r\n}\r\n\r\nexport interface TpPasswordResetUserApprover {\r\n name?: string;\r\n email?: string;\r\n state?: TpClaimApproverState;\r\n}\r\n\r\nexport interface TpPasswordResetUserSubAssembly {\r\n singleReject?: boolean;\r\n quorum?: number;\r\n approvers?: TpPasswordResetUserApprover[];\r\n}\r\n\r\nexport interface TpPasswordResetUserAssembly {\r\n singleReject?: boolean;\r\n quorum?: number;\r\n subAssemblies?: TpPasswordResetUserSubAssembly[];\r\n}\r\n\r\nexport interface TpPasswordResetUserNode {\r\n username?: string;\r\n resetUsername?: string;\r\n state?: TpClaimState;\r\n passKey?: PassKeyNode;\r\n masterKey?: KeyNode;\r\n pxk?: KeyNode;\r\n sessionEncryptionKey?: string;\r\n approvals?: TpPasswordResetUserApprovalNode[];\r\n assemblyCipherData?: string;\r\n wrappedAssemblyKeyVerifierPrk?: string;\r\n assembly?: TpPasswordResetUserAssembly;\r\n}\r\n\r\nexport interface TpPasswordResetNode extends Node, TimeStamped {\r\n assembly?: TpAssemblyNode;\r\n request?: TpPasswordResetRequestNode;\r\n applied?: boolean;\r\n}\r\n\r\nexport interface TpAssemblyNode extends Node, TimeStamped {\r\n id?: ID;\r\n singleReject?: boolean;\r\n quorum?: number;\r\n subjectKey?: KeyNode;\r\n assemblyKey?: KeyNode;\r\n assemblyCipherData?: string;\r\n assemblyCipherDataClearJson?: any;\r\n subAssemblies?: Connection<TpSubAssemblyNode>;\r\n}\r\n\r\nexport interface TpSubAssemblyNode extends Node, TimeStamped {\r\n singleReject?: boolean;\r\n quorum?: number;\r\n subjectCipherData?: string;\r\n subjectCipherDataClearJson?: string;\r\n approvers?: Connection<TpAssemblyApproverNode>;\r\n}\r\n\r\nexport interface TpAssemblyApproverNode extends Node, TimeStamped {\r\n sharedKey?: KeyNode;\r\n sharedCipherData?: string;\r\n sharedCipherApprovalData?: string;\r\n tp?: TpNode;\r\n}\r\n\r\nexport interface SharedTpPasswordResetNode extends Node, TimeStamped {\r\n assembly?: SharedTpAssemblyNode;\r\n tp?: TpNode;\r\n sharedRequest?: SharedTpPasswordResetRequestNode;\r\n}\r\n\r\nexport interface SharedTpAssemblyNode extends Node, TimeStamped {\r\n asApprovers?: Connection<TpAssemblyAsApproverNode>;\r\n}\r\n\r\nexport interface TpAssemblyAsApproverNode extends Node, TimeStamped {\r\n sharedKey?: KeyNode;\r\n sharedCipherData?: string;\r\n}\r\n\r\nexport interface SharedTpPasswordResetRequestNode extends Node, TimeStamped {\r\n claim?: SharedTpClaimNode;\r\n pxk?: KeyNode;\r\n}\r\n\r\nexport interface SharedTpClaimNode extends Node, TimeStamped {\r\n state?: TpClaimState;\r\n asClaimApprovers?: Connection<SharedTpClaimApproverNode>;\r\n}\r\n\r\nexport interface SharedTpClaimApproverNode extends Node, TimeStamped {\r\n state?: TpClaimApproverState;\r\n sharedKey?: KeyNode;\r\n sharedCipherApprovalData?: string;\r\n sharedCipherPartialAssemblyKey?: string;\r\n receiverApprovals?: Connection<SharedTpClaimReceiverApprovalNode>;\r\n}\r\n\r\nexport interface SharedTpClaimReceiverApprovalNode extends Node, TimeStamped {\r\n pxk?: KeyNode;\r\n}\r\n\r\nexport enum LockState {\r\n UNLOCKED = 'UNLOCKED',\r\n MUTEX_LOCKED = 'MUTEX_LOCKED',\r\n}\r\n","import { Hub } from '@aws-amplify/core';\r\nimport { Inject, Injectable, Injector, NgZone } from '@angular/core';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { KeyGraphService } from '../cryptography/key-graph.service';\r\nimport { LifeReadyConfig, LR_CONFIG } from '../life-ready.config';\r\nimport * as slip from '../cryptography/slip39.service';\r\nimport { JWK } from 'node-jose';\r\nimport { LrBadStateException, LrException } from '../_common/exceptions';\r\nimport {\r\n CompleteTpPasswordResetRequestMutation,\r\n CreateTpAssemblyKeyChallengeMutation,\r\n PreCompleteTpPasswordResetRequestMutation,\r\n} from './tp-password-reset.gql';\r\nimport { PasswordService } from '../auth/password.service';\r\nimport { HttpClient } from '@angular/common/http';\r\nimport { AuthClass } from '@aws-amplify/auth/lib-esm/Auth';\r\nimport {\r\n RequestResetResult,\r\n TpPasswordResetService,\r\n} from './tp-password-reset.service';\r\nimport { ISignUpResult } from 'amazon-cognito-identity-js';\r\nimport { LifeReadyAuthService } from '../auth/life-ready-auth.service';\r\nimport { KeyFactoryService } from '../cryptography/key-factory.service';\r\nimport { TpClaimState, TpPasswordResetUserNode } from '../api/types';\r\nimport { LrMutation, LrService } from '../api/lr-graphql';\r\nimport { RunOutsideAngular } from '../_common/run-outside-angular';\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class TpPasswordResetUserService extends LrService {\r\n private readonly CLIENT_NONCE_LENGTH = 32;\r\n private resetUser: TpPasswordResetUserNode;\r\n\r\n constructor(\r\n private ngZone: NgZone,\r\n private injector: Injector,\r\n @Inject(LR_CONFIG) private config: LifeReadyConfig,\r\n private keyFactory: KeyFactoryService,\r\n private encryptionService: EncryptionService,\r\n private keyGraphService: KeyGraphService,\r\n private slip39Service: slip.Slip39Service,\r\n private passwordService: PasswordService,\r\n private http: HttpClient,\r\n private auth: AuthClass,\r\n private lrAuth: LifeReadyAuthService\r\n ) {\r\n super(injector);\r\n }\r\n\r\n async verifyEmailContact(email): Promise<{ claimId: string }> {\r\n const params = {\r\n email,\r\n };\r\n return this.http\r\n .post<any>(\r\n `${this.config.authUrl}tp/password-reset/verify-contact/`,\r\n params\r\n )\r\n .toPromise();\r\n }\r\n\r\n async verifyContactRespond(\r\n claimId: string,\r\n claimCode: string\r\n ): Promise<string> {\r\n const { token } = await this.http\r\n .post<{ token }>(`${this.config.authUrl}cove/respond/`, {\r\n claim_id: claimId,\r\n v_code: claimCode,\r\n })\r\n .toPromise();\r\n return token;\r\n }\r\n\r\n async requestReset(\r\n password: string,\r\n claimId: string,\r\n claimToken: string\r\n ): Promise<{\r\n requestResetResult: RequestResetResult;\r\n signUpResult: ISignUpResult;\r\n }> {\r\n // Generate the key materials\r\n const passKeyBundle = await this.passwordService.createPassKeyBundle(\r\n password\r\n );\r\n\r\n const masterKey = await this.keyFactory.createKey();\r\n const wrappedMasterKey = await this.encryptionService.encrypt(\r\n passKeyBundle.passKey,\r\n masterKey.toJSON(true)\r\n );\r\n\r\n // Ephemeral PKC key\r\n const prk = await this.keyFactory.createPkcKey();\r\n const masterKeyWrappedPrk = await this.encryptionService.encrypt(\r\n masterKey,\r\n prk.toJSON(true)\r\n );\r\n\r\n // API call to setup reset request\r\n const requestResetResult = await this.http\r\n .post<RequestResetResult>(\r\n `${this.config.authUrl}tp/password-reset/request/`,\r\n {\r\n claimId,\r\n claimToken,\r\n pass_key_params: passKeyBundle.passKeyParams,\r\n pass_idp_params: passKeyBundle.passIdpParams,\r\n pass_idp_verifier_pbk: passKeyBundle.passIdpVerifier.toJSON(), // public key\r\n wrapped_pass_idp_verifier_prk:\r\n passKeyBundle.wrappedPassIdpVerifierPrk,\r\n wrapped_master_key: wrappedMasterKey,\r\n pbk: prk.toJSON(), // ephemeral public key\r\n master_key_wrapped_prk: masterKeyWrappedPrk,\r\n }\r\n )\r\n .toPromise();\r\n\r\n console.log(requestResetResult);\r\n console.log(\r\n 'Using new password: ',\r\n this.passwordService.getPassIdpString(passKeyBundle.passIdp)\r\n );\r\n\r\n // API call to create user on cognito\r\n const signUpResult = await this.auth.signUp({\r\n username: requestResetResult.reset_username,\r\n password: this.passwordService.getPassIdpString(passKeyBundle.passIdp),\r\n clientMetadata: {\r\n tp_password_reset_request: JSON.stringify({\r\n id: requestResetResult.id,\r\n associate_reset_user_token:\r\n requestResetResult.associate_reset_user_token,\r\n }),\r\n },\r\n });\r\n\r\n console.log('requestRest done: ', signUpResult);\r\n\r\n return {\r\n requestResetResult,\r\n signUpResult,\r\n };\r\n }\r\n\r\n async getResetUser(\r\n reload: boolean = false\r\n ): Promise<TpPasswordResetUserNode> {\r\n if (!reload && this.resetUser) {\r\n return this.resetUser;\r\n }\r\n this.resetUser = await this.lrAuth.loadResetUser();\r\n return this.resetUser;\r\n }\r\n\r\n private async recoverAssemblyKey(\r\n resetUser: TpPasswordResetUserNode\r\n ): Promise<JWK.Key> {\r\n // Recover the assembly key.\r\n let assemblyKeyParams: object;\r\n\r\n const prk = await this.keyGraphService.getKey(resetUser.pxk.id);\r\n\r\n const shares = await Promise.all(\r\n resetUser.approvals.map(async (approval) => {\r\n const partialAssemblyKey = await this.encryptionService.decrypt(\r\n prk,\r\n approval.receiverCipherPartialAssemblyKey\r\n );\r\n\r\n if (assemblyKeyParams) {\r\n if (\r\n JSON.stringify(assemblyKeyParams) !==\r\n JSON.stringify(partialAssemblyKey.assemblyKeyParams)\r\n ) {\r\n throw new LrBadStateException(\r\n 'The assembly key parameters are different between the approvals.'\r\n );\r\n }\r\n } else {\r\n assemblyKeyParams = partialAssemblyKey.assemblyKeyParams;\r\n }\r\n return partialAssemblyKey.slip39.share.mnemonics;\r\n })\r\n );\r\n\r\n console.log('recoverAssemblyKey()', shares);\r\n\r\n const rawAssemblyKey = await this.slip39Service.recoverSecret(\r\n shares,\r\n TpPasswordResetService.SLIP39_PASSPHRASE\r\n );\r\n\r\n return JWK.asKey({\r\n ...assemblyKeyParams,\r\n k: rawAssemblyKey,\r\n });\r\n }\r\n\r\n async completeRequest(newPassword: string): Promise<void> {\r\n const resetUser = await this.getResetUser(true);\r\n if (resetUser.state !== TpClaimState.APPROVED) {\r\n throw new LrBadStateException(\r\n 'Password reset request has not been approved.'\r\n );\r\n }\r\n\r\n // --------------------------------------------------------------\r\n // Prepare all materials to ensure there are no errors.\r\n // --------------------------------------------------------------\r\n const assemblyKey = await this.recoverAssemblyKey(resetUser);\r\n\r\n const { rootKey } = await this.encryptionService.decrypt(\r\n assemblyKey,\r\n resetUser.assemblyCipherData\r\n );\r\n console.log(rootKey);\r\n\r\n // Making sure it's a valid key.\r\n const rootKeyJwk = await JWK.asKey(rootKey);\r\n\r\n const masterKey = await this.keyGraphService.getKey(resetUser.masterKey.id);\r\n\r\n const masterKeyWrappedRootKey = await this.encryptionService.encryptToString(\r\n masterKey.jwk,\r\n rootKeyJwk.toJSON(true)\r\n );\r\n\r\n // The new password\r\n const newPassIdpResult = await this.keyFactory.derivePassIdp({\r\n password: newPassword,\r\n ...resetUser.passKey.passIdpParams,\r\n });\r\n\r\n const newIdpPassword = this.passwordService.getPassIdpString(\r\n newPassIdpResult.jwk\r\n );\r\n\r\n // --------------------------------------------------------------\r\n // Get assembly key challenge\r\n // --------------------------------------------------------------\r\n const challenge = (\r\n await this.mutate(\r\n new LrMutation({\r\n mutation: CreateTpAssemblyKeyChallengeMutation,\r\n variables: {\r\n input: {},\r\n },\r\n }),\r\n {\r\n includeKeyGraph: false,\r\n }\r\n )\r\n ).createTpAssemblyKeyChallenge.challenge;\r\n\r\n console.log(challenge);\r\n\r\n // Sign the challenge\r\n // Generate a client side nonce that's no in the server's control.\r\n challenge.clientNonce = this.keyFactory.randomString(\r\n this.CLIENT_NONCE_LENGTH\r\n );\r\n console.log(challenge);\r\n\r\n const assemblyKeyVerifierPrk = await this.encryptionService.decrypt(\r\n assemblyKey,\r\n resetUser.wrappedAssemblyKeyVerifierPrk\r\n );\r\n const signedChallenge = await this.encryptionService.sign(\r\n assemblyKeyVerifierPrk,\r\n challenge\r\n );\r\n\r\n // --------------------------------------------------------------\r\n // Change password for the original user\r\n // --------------------------------------------------------------\r\n const tempIdpPassword = (\r\n await this.mutate(\r\n new LrMutation({\r\n mutation: PreCompleteTpPasswordResetRequestMutation,\r\n variables: {\r\n input: {\r\n signedChallenge: JSON.stringify(signedChallenge),\r\n },\r\n },\r\n }),\r\n {\r\n includeKeyGraph: false,\r\n }\r\n )\r\n ).preCompleteTpPasswordResetRequest.idpPassword;\r\n\r\n // --------------------------------------------------------------\r\n // Login as the original user using new temporary password\r\n // --------------------------------------------------------------\r\n // At this point, the original account's password has been changed\r\n // to a temporary password. It is no longer possible for the user\r\n // to use the original password to login. Any successful login\r\n // can only be using the temporary password. So it's safe to assume\r\n // that we want to \"complete\" the password reset.\r\n\r\n // The maybe 2FA so we listen for the auth event from Amplify.\r\n const retPromise = new Promise<void>((resolve) => {\r\n const listener = async (data) => {\r\n if (data.payload.event !== 'signIn') {\r\n return;\r\n }\r\n\r\n Hub.remove('auth', listener);\r\n\r\n console.log(data.payload);\r\n\r\n await this.auth.signIn(resetUser.username, newIdpPassword);\r\n\r\n // Switch over to the new set of keys\r\n await this.mutate(\r\n new LrMutation({\r\n mutation: CompleteTpPasswordResetRequestMutation,\r\n variables: {\r\n input: {\r\n masterKeyWrappedRootKey,\r\n masterKeyId: masterKey.id,\r\n },\r\n },\r\n })\r\n );\r\n\r\n resolve();\r\n };\r\n\r\n Hub.listen('auth', listener);\r\n });\r\n\r\n // Signin as the original user. Password has been reset to temporary one. It should return\r\n // with NEW_PASSWORD_REQUIRED\r\n let user = await this.auth.signIn(resetUser.username, tempIdpPassword, {\r\n noProxy: 'true',\r\n });\r\n\r\n if (user.challengeName !== 'NEW_PASSWORD_REQUIRED') {\r\n throw new LrException({\r\n message:\r\n 'Internal error. Expecting Cognito to have done a password reset after call to PreCompleteTpPasswordResetRequestMutation.',\r\n });\r\n }\r\n\r\n // Set new password on Idp\r\n // the awsFetch() function passes NEW_PASSWORD_REQUIRED directly to AWS without\r\n // going through the proxy.\r\n user = await this.auth.completeNewPassword(user, newIdpPassword, {});\r\n\r\n return retPromise;\r\n }\r\n}\r\n","import { Injectable, Injector, NgZone } from '@angular/core';\r\nimport { JWK } from 'node-jose';\r\nimport {\r\n LrGraphQLService,\r\n LrMergedMutation,\r\n LrMutation,\r\n LrMutationBase,\r\n LrService,\r\n} from '../api/lr-graphql';\r\nimport { TpAssemblyState, TpClaimApproverState } from '../api/types';\r\nimport { EncryptionService } from '../cryptography/encryption.service';\r\nimport { LrBadStateException } from '../_common/exceptions';\r\nimport { RunOutsideAngular } from '../_common/run-outside-angular';\r\nimport {\r\n ApproveTpPasswordResetRequestMutation,\r\n RejectTpPasswordResetRequestMutation,\r\n SharedTpPasswordResetQuery,\r\n SharedTpPasswordResetsQuery,\r\n} from './tp-password-reset.gql';\r\n\r\n@RunOutsideAngular({\r\n ngZoneName: 'ngZone',\r\n})\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class TpPasswordResetRequestService extends LrService {\r\n constructor(\r\n private ngZone: NgZone,\r\n private injector: Injector,\r\n private encryptionService: EncryptionService\r\n ) {\r\n super(injector);\r\n }\r\n\r\n async getSharedResets() {\r\n return (\r\n await this.query({\r\n query: SharedTpPasswordResetsQuery,\r\n })\r\n ).sharedTpPasswordResets;\r\n }\r\n\r\n async getSharedReset(id) {\r\n return (\r\n await this.query({\r\n query: SharedTpPasswordResetQuery,\r\n variables: {\r\n id,\r\n },\r\n })\r\n ).sharedTpPasswordReset;\r\n }\r\n\r\n private activeRequestOrRaise(sharedReset): void {\r\n const state = sharedReset.sharedRequest.claim.state;\r\n if (state !== TpAssemblyState.CLAIMED) {\r\n throw new LrBadStateException(`Claim is already in ${state} state.`);\r\n }\r\n }\r\n\r\n rejectRequest(sharedResetId: string) {\r\n return this.mutate(this.rejectRequestMutation(sharedResetId));\r\n }\r\n\r\n async rejectRequestMutation(sharedResetId: string) {\r\n const sharedReset = await this.getSharedReset(sharedResetId);\r\n\r\n this.activeRequestOrRaise(sharedReset);\r\n\r\n return LrMergedMutation.create(\r\n sharedReset.sharedRequest.claim.asClaimApprovers.edges\r\n .filter((edge) => edge.node.state === TpClaimApproverState.CLAIMED)\r\n .map(\r\n (edge) =>\r\n new LrMutation({\r\n mutation: RejectTpPasswordResetRequestMutation,\r\n variables: { input: { claimApproverId: edge.node.id } },\r\n })\r\n )\r\n );\r\n }\r\n\r\n // ?? TODO The return from this should not be any.\r\n approveRequest(sharedResetId: string, pbkFingerPrint?: string) {\r\n return this.mutate(\r\n this.approveRequestMutation(sharedResetId, pbkFingerPrint)\r\n );\r\n }\r\n\r\n async approveRequestMutation(sharedResetId: string, pbkFingerPrint?: string) {\r\n const sharedReset = await this.getSharedReset(sharedResetId);\r\n\r\n this.activeRequestOrRaise(sharedReset);\r\n\r\n const pbk = await JWK.asKey(JSON.parse(sharedReset.sharedRequest.pxk.pbk));\r\n console.log(pbk.toJSON());\r\n\r\n // TODO <AZ> Verify pbk against pbkFingerPrint\r\n\r\n const claimApprovers = sharedReset.sharedRequest.claim.asClaimApprovers.edges.filter(\r\n (edge) => edge.node.state === TpClaimApproverState.CLAIMED\r\n );\r\n\r\n // A single approver may belong to multiple sub-assemblies. We approve them all here in a single\r\n // transaction.\r\n return LrMergedMutation.create(\r\n await Promise.all(\r\n claimApprovers.map(async (approverEdge) => {\r\n const ca = approverEdge.node;\r\n const input = {\r\n claimApproverId: ca.id,\r\n receiverApprovals: await Promise.all(\r\n ca.receiverApprovals.edges.map(async (receiverEdge) => {\r\n const ra = receiverEdge.node;\r\n return {\r\n receiverApprovalId: ra.id,\r\n receiverCipher: '',\r\n receiverCipherPartialAssemblyKey: await this.encryptionService.encryptToString(\r\n pbk,\r\n ca.sharedCipherPartialAssemblyKeyClearJson\r\n ),\r\n };\r\n })\r\n ),\r\n };\r\n\r\n console.log(input);\r\n\r\n return new LrMutation({\r\n mutation: ApproveTpPasswordResetRequestMutation,\r\n variables: {\r\n input,\r\n },\r\n });\r\n })\r\n )\r\n );\r\n }\r\n}\r\n","/*\r\n * Public API Surface of lr-auth\r\n */\r\n\r\nexport * from './lib/_common/exceptions';\r\n\r\nexport * from './lib/api/file.service';\r\nexport * from './lib/api/key-exchange.service';\r\nexport * from './lib/api/key-exchange.types';\r\nexport * from './lib/api/key-exchange.gql';\r\nexport * from './lib/api/lr-apollo.service';\r\nexport * from './lib/api/persist.service';\r\nexport * from './lib/api/message.service';\r\nexport * from './lib/_common/queries.gql';\r\n\r\nexport * from './lib/auth/auth.types';\r\nexport * from './lib/auth/auth.config';\r\nexport * from './lib/auth/lbop.service';\r\nexport * from './lib/auth/life-ready-auth.service';\r\nexport * from './lib/auth/password.service';\r\nexport * from './lib/auth/register.service';\r\nexport * from './lib/auth/two-factor.service';\r\nexport * from './lib/auth/idle.types';\r\nexport * from './lib/auth/idle.service';\r\n\r\nexport * from './lib/cryptography/encryption.service';\r\nexport * from './lib/cryptography/key.service';\r\nexport * from './lib/cryptography/key-factory.service';\r\nexport * from './lib/cryptography/key-graph.service';\r\nexport * from './lib/cryptography/key-meta.service';\r\nexport * from './lib/cryptography/cryptography.types';\r\nexport * from './lib/cryptography/slip39.service';\r\nexport * from './lib/cryptography/web-crypto.service';\r\n\r\nexport * from './lib/category/category-meta.service';\r\nexport * from './lib/category/category.types';\r\nexport * from './lib/category/category.gql';\r\nexport * from './lib/category/category.service';\r\n\r\nexport * from './lib/record/record-attachment.service';\r\nexport * from './lib/record/record.types';\r\nexport * from './lib/record/record.gql';\r\nexport * from './lib/record/record.service';\r\n\r\nexport * from './lib/record-type/record-type.types';\r\nexport * from './lib/record-type/record-type.service';\r\n\r\nexport * from './lib/trusted-parties/trusted-party.types';\r\nexport * from './lib/trusted-parties/trusted-party.gql';\r\nexport * from './lib/trusted-parties/trusted-party.service';\r\n\r\nexport * from './lib/scenario/scenario.types';\r\nexport * from './lib/scenario/scenario.gql';\r\nexport * from './lib/scenario/scenario.service';\r\nexport * from './lib/scenario/scenario-setup.service';\r\n\r\nexport * from './lib/scenario/approvals/scenario-approval.types';\r\nexport * from './lib/scenario/approvals/scenario-approval.gql';\r\nexport * from './lib/scenario/approvals/scenario-approver.service';\r\n\r\nexport * from './lib/scenario/claimants/scenario-claimant.types';\r\nexport * from './lib/scenario/claimants/scenario-claimant.gql';\r\nexport * from './lib/scenario/claimants/scenario-claimant.service';\r\n\r\nexport * from './lib/scenario/receivers/scenario-receiver.types';\r\nexport * from './lib/scenario/receivers/scenario-receiver.gql';\r\nexport * from './lib/scenario/receivers/scenario-receiver.service';\r\n\r\nexport * from './lib/users/profile.gql';\r\nexport * from './lib/users/profile.service';\r\nexport * from './lib/users/profile-details.service';\r\nexport * from './lib/users/profile.types';\r\nexport * from './lib/users/user.gql';\r\nexport * from './lib/users/user.service';\r\nexport * from './lib/users/user.types';\r\n\r\nexport * from './lib/life-ready.config';\r\nexport * from './lib/life-ready.module';\r\nexport * from './lib/plan/plan.types';\r\nexport * from './lib/plan/plan.service';\r\nexport * from './lib/search/search.types';\r\nexport * from './lib/search/search.service';\r\n\r\nexport { gqlTyped } from './lib/_common/ast';\r\n\r\nexport * from './lib/api/lr-graphql';\r\nexport * from './lib/api/query-processor';\r\nexport * from './lib/api/contact-card2.service';\r\nexport * from './lib/api/item2.service';\r\nexport * from './lib/api/key-exchange2.service';\r\nexport * from './lib/api/shared-contact-card2.service';\r\nexport * from './lib/api/lock.service';\r\nexport * from './lib/trusted-parties/trusted-party2.service';\r\nexport * from './lib/trusted-parties/tp-password-reset.service';\r\nexport * from './lib/trusted-parties/tp-password-reset-user.service';\r\nexport * from './lib/trusted-parties/tp-password-reset-request.service';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n\nexport {RunOutsideAngular as ɵd} from './lib/_common/run-outside-angular';\nexport {LrGraphQLService as ɵb,LrService as ɵg} from './lib/api/lr-graphql';\nexport {TpPasswordResetProcessorService as ɵc} from './lib/api/query-processor/tp-password-reset-processor.service';\nexport {SharedContactCardFields as ɵe,SharedContactCardService as ɵf} from './lib/api/shared-contact-card.service';\nexport {TimeService as ɵa} from './lib/api/time.service';"],"names":["moment","KFS","_","CreateContactCardMutation","UpdateContactCardMutation","ArchiveDirectoryMutation","UnarchiveDirectoryMutation","ContactCardQuery","DeleteContactCardMutation","lodash","ast.name","KeyExchangeState","KeyExchangeMode","CreateFileMutation","DeleteFileMutation","ApproverFields","slip.Assembly","slip.SubAssembly","slip.Slip39Service"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAGgB,iBAAiB,CAAC,MAAmC;IACnE,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO;IAEtC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM;QAClC,IAAI,EAAE,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI;Q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