@lifeready/core 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/README.md +62 -62
  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 +16 -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 +500 -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 +129 -0
  98. package/esm2015/lib/trusted-parties/tp-password-reset.constants.js +4 -0
  99. package/esm2015/lib/trusted-parties/tp-password-reset.gql.js +232 -0
  100. package/esm2015/lib/trusted-parties/tp-password-reset.service.js +299 -0
  101. package/esm2015/lib/trusted-parties/trusted-party.gql.js +148 -0
  102. package/esm2015/lib/trusted-parties/trusted-party.service.js +326 -0
  103. package/esm2015/lib/trusted-parties/trusted-party.types.js +41 -0
  104. package/esm2015/lib/trusted-parties/trusted-party2.gql.js +87 -0
  105. package/esm2015/lib/trusted-parties/trusted-party2.service.js +215 -0
  106. package/esm2015/lib/users/profile-details.service.js +214 -0
  107. package/esm2015/lib/users/profile.gql.js +97 -0
  108. package/esm2015/lib/users/profile.service.js +169 -0
  109. package/esm2015/lib/users/profile.types.js +34 -0
  110. package/esm2015/lib/users/user.gql.js +60 -0
  111. package/esm2015/lib/users/user.service.js +79 -0
  112. package/esm2015/lib/users/user.types.js +5 -0
  113. package/esm2015/lifeready-core.js +10 -0
  114. package/esm2015/public-api.js +81 -0
  115. package/fesm2015/lifeready-core.js +13314 -0
  116. package/fesm2015/lifeready-core.js.map +1 -0
  117. package/lib/_common/ast.d.ts +11 -0
  118. package/lib/_common/deferred-promise.d.ts +12 -0
  119. package/lib/_common/exceptions.d.ts +109 -0
  120. package/lib/_common/queries.gql.d.ts +10 -0
  121. package/lib/_common/run-outside-angular.d.ts +14 -0
  122. package/{src/lib/_common/types.ts → lib/_common/types.d.ts} +10 -13
  123. package/lib/_common/utils.d.ts +3 -0
  124. package/lib/api/contact-card.gql.d.ts +7 -0
  125. package/lib/api/contact-card.service.d.ts +52 -0
  126. package/lib/api/contact-card2.gql.d.ts +34 -0
  127. package/lib/api/contact-card2.service.d.ts +49 -0
  128. package/lib/api/file.service.d.ts +18 -0
  129. package/lib/api/item2.gql.d.ts +96 -0
  130. package/lib/api/item2.service.d.ts +177 -0
  131. package/lib/api/key-exchange.gql.d.ts +9 -0
  132. package/lib/api/key-exchange.service.d.ts +39 -0
  133. package/lib/api/key-exchange.types.d.ts +196 -0
  134. package/lib/api/key-exchange2.gql.d.ts +125 -0
  135. package/lib/api/key-exchange2.service.d.ts +187 -0
  136. package/lib/api/lock.gql.d.ts +27 -0
  137. package/lib/api/lock.service.d.ts +25 -0
  138. package/lib/api/lr-apollo.service.d.ts +15 -0
  139. package/{src/lib/api/lr-graphql/index.ts → lib/api/lr-graphql/index.d.ts} +5 -5
  140. package/lib/api/lr-graphql/lr-graphql.service.d.ts +60 -0
  141. package/lib/api/lr-graphql/lr-merged-mutation.d.ts +27 -0
  142. package/lib/api/lr-graphql/lr-mutation-base.d.ts +28 -0
  143. package/lib/api/lr-graphql/lr-mutation.d.ts +8 -0
  144. package/lib/api/lr-graphql/lr.service.d.ts +9 -0
  145. package/lib/api/message.service.d.ts +58 -0
  146. package/lib/api/persist.service.d.ts +31 -0
  147. package/lib/api/query-processor/common-processors.service.d.ts +36 -0
  148. package/{src/lib/api/query-processor/index.ts → lib/api/query-processor/index.d.ts} +2 -2
  149. package/lib/api/query-processor/query-processor.service.d.ts +18 -0
  150. package/lib/api/query-processor/tp-password-reset-processor.service.d.ts +15 -0
  151. package/lib/api/shared-contact-card.service.d.ts +33 -0
  152. package/lib/api/shared-contact-card2.gql.d.ts +36 -0
  153. package/lib/api/shared-contact-card2.service.d.ts +45 -0
  154. package/lib/api/time.service.d.ts +16 -0
  155. package/lib/api/types/graphql.types.d.ts +29 -0
  156. package/{src/lib/api/types/index.ts → lib/api/types/index.d.ts} +2 -2
  157. package/lib/api/types/lr-graphql.types.d.ts +385 -0
  158. package/lib/auth/auth.config.d.ts +5 -0
  159. package/lib/auth/auth.gql.d.ts +15 -0
  160. package/lib/auth/auth.types.d.ts +66 -0
  161. package/lib/auth/idle.service.d.ts +40 -0
  162. package/lib/auth/idle.types.d.ts +10 -0
  163. package/lib/auth/lbop.service.d.ts +91 -0
  164. package/lib/auth/life-ready-auth.service.d.ts +59 -0
  165. package/lib/auth/password.service.d.ts +78 -0
  166. package/lib/auth/register.service.d.ts +25 -0
  167. package/lib/auth/two-factor.service.d.ts +15 -0
  168. package/lib/category/category-meta.service.d.ts +23 -0
  169. package/lib/category/category.gql.d.ts +45 -0
  170. package/lib/category/category.service.d.ts +67 -0
  171. package/lib/category/category.types.d.ts +79 -0
  172. package/lib/cryptography/cryptography.types.d.ts +83 -0
  173. package/lib/cryptography/encryption.service.d.ts +41 -0
  174. package/lib/cryptography/key-factory.service.d.ts +38 -0
  175. package/lib/cryptography/key-graph.service.d.ts +33 -0
  176. package/lib/cryptography/key-meta.service.d.ts +44 -0
  177. package/lib/cryptography/key.service.d.ts +36 -0
  178. package/lib/cryptography/slip39.service.d.ts +43 -0
  179. package/lib/cryptography/web-crypto.service.d.ts +5 -0
  180. package/lib/life-ready.config.d.ts +14 -0
  181. package/lib/life-ready.module.d.ts +5 -0
  182. package/lib/plan/plan.gql.d.ts +11 -0
  183. package/lib/plan/plan.service.d.ts +33 -0
  184. package/lib/plan/plan.types.d.ts +31 -0
  185. package/lib/record/record-attachment.service.d.ts +16 -0
  186. package/lib/record/record.gql.d.ts +14 -0
  187. package/lib/record/record.service.d.ts +25 -0
  188. package/lib/record/record.types.d.ts +57 -0
  189. package/lib/record-type/record-type.service.d.ts +11 -0
  190. package/lib/record-type/record-type.types.d.ts +50 -0
  191. package/lib/scenario/approvals/scenario-approval.gql.d.ts +7 -0
  192. package/lib/scenario/approvals/scenario-approval.types.d.ts +63 -0
  193. package/lib/scenario/approvals/scenario-approver.service.d.ts +32 -0
  194. package/lib/scenario/claimants/scenario-claimant.gql.d.ts +5 -0
  195. package/lib/scenario/claimants/scenario-claimant.service.d.ts +17 -0
  196. package/lib/scenario/claimants/scenario-claimant.types.d.ts +18 -0
  197. package/lib/scenario/receivers/scenario-receiver.gql.d.ts +8 -0
  198. package/lib/scenario/receivers/scenario-receiver.service.d.ts +30 -0
  199. package/lib/scenario/receivers/scenario-receiver.types.d.ts +54 -0
  200. package/lib/scenario/scenario-setup.service.d.ts +22 -0
  201. package/lib/scenario/scenario.gql.d.ts +34 -0
  202. package/lib/scenario/scenario.service.d.ts +58 -0
  203. package/lib/scenario/scenario.types.d.ts +217 -0
  204. package/lib/search/search.gql.d.ts +1 -0
  205. package/lib/search/search.service.d.ts +25 -0
  206. package/lib/search/search.types.d.ts +20 -0
  207. package/lib/trusted-parties/tp-password-reset-request.service.d.ts +20 -0
  208. package/lib/trusted-parties/tp-password-reset-user.service.d.ts +35 -0
  209. package/lib/trusted-parties/tp-password-reset.constants.d.ts +3 -0
  210. package/lib/trusted-parties/tp-password-reset.gql.d.ts +218 -0
  211. package/lib/trusted-parties/tp-password-reset.service.d.ts +130 -0
  212. package/lib/trusted-parties/trusted-party.gql.d.ts +9 -0
  213. package/lib/trusted-parties/trusted-party.service.d.ts +44 -0
  214. package/lib/trusted-parties/trusted-party.types.d.ts +102 -0
  215. package/lib/trusted-parties/trusted-party2.gql.d.ts +79 -0
  216. package/lib/trusted-parties/trusted-party2.service.d.ts +114 -0
  217. package/lib/users/profile-details.service.d.ts +21 -0
  218. package/lib/users/profile.gql.d.ts +11 -0
  219. package/lib/users/profile.service.d.ts +35 -0
  220. package/lib/users/profile.types.d.ts +96 -0
  221. package/lib/users/user.gql.d.ts +9 -0
  222. package/lib/users/user.service.d.ts +12 -0
  223. package/lib/users/user.types.d.ts +23 -0
  224. package/lifeready-core.d.ts +9 -0
  225. package/lifeready-core.metadata.json +1 -0
  226. package/package.json +29 -21
  227. package/{src/public-api.ts → public-api.d.ts} +77 -96
  228. package/karma.conf.js +0 -32
  229. package/ng-package.json +0 -26
  230. package/src/lib/_common/ast.ts +0 -75
  231. package/src/lib/_common/deferred-promise.ts +0 -35
  232. package/src/lib/_common/exceptions.ts +0 -189
  233. package/src/lib/_common/queries.gql.ts +0 -200
  234. package/src/lib/_common/run-outside-angular.ts +0 -125
  235. package/src/lib/_common/tests.ts +0 -82
  236. package/src/lib/_common/utils.ts +0 -57
  237. package/src/lib/api/api-mutation.spec.ts +0 -547
  238. package/src/lib/api/api-query.spec.ts +0 -40
  239. package/src/lib/api/contact-card.gql.ts +0 -85
  240. package/src/lib/api/contact-card.service.spec.ts +0 -249
  241. package/src/lib/api/contact-card.service.ts +0 -228
  242. package/src/lib/api/contact-card2.gql.ts +0 -93
  243. package/src/lib/api/contact-card2.service.spec.ts +0 -297
  244. package/src/lib/api/contact-card2.service.ts +0 -139
  245. package/src/lib/api/file.service.spec.ts +0 -14
  246. package/src/lib/api/file.service.ts +0 -81
  247. package/src/lib/api/item2.gql.ts +0 -211
  248. package/src/lib/api/item2.service.spec.ts +0 -1043
  249. package/src/lib/api/item2.service.ts +0 -481
  250. package/src/lib/api/key-exchange.gql.ts +0 -196
  251. package/src/lib/api/key-exchange.service.spec.ts +0 -470
  252. package/src/lib/api/key-exchange.service.ts +0 -731
  253. package/src/lib/api/key-exchange.types.ts +0 -235
  254. package/src/lib/api/key-exchange2.gql.ts +0 -310
  255. package/src/lib/api/key-exchange2.service.spec.ts +0 -892
  256. package/src/lib/api/key-exchange2.service.ts +0 -875
  257. package/src/lib/api/lock.gql.ts +0 -67
  258. package/src/lib/api/lock.service.spec.ts +0 -549
  259. package/src/lib/api/lock.service.ts +0 -57
  260. package/src/lib/api/lr-apollo.service.spec.ts +0 -27
  261. package/src/lib/api/lr-apollo.service.ts +0 -43
  262. package/src/lib/api/lr-graphql/lr-graphql.service.ts +0 -313
  263. package/src/lib/api/lr-graphql/lr-merged-mutation.ts +0 -377
  264. package/src/lib/api/lr-graphql/lr-mutation-base.ts +0 -67
  265. package/src/lib/api/lr-graphql/lr-mutation.ts +0 -74
  266. package/src/lib/api/lr-graphql/lr.service.ts +0 -28
  267. package/src/lib/api/message.service.spec.ts +0 -20
  268. package/src/lib/api/message.service.ts +0 -210
  269. package/src/lib/api/persist.service.spec.ts +0 -209
  270. package/src/lib/api/persist.service.ts +0 -220
  271. package/src/lib/api/query-processor/common-processors.service.ts +0 -148
  272. package/src/lib/api/query-processor/query-processor.service.ts +0 -240
  273. package/src/lib/api/query-processor/tp-password-reset-processor.service.ts +0 -177
  274. package/src/lib/api/shared-contact-card.service.ts +0 -156
  275. package/src/lib/api/shared-contact-card2.gql.ts +0 -76
  276. package/src/lib/api/shared-contact-card2.service.ts +0 -154
  277. package/src/lib/api/time.service.spec.ts +0 -48
  278. package/src/lib/api/time.service.ts +0 -155
  279. package/src/lib/api/types/graphql.types.ts +0 -48
  280. package/src/lib/api/types/lr-graphql.types.ts +0 -467
  281. package/src/lib/auth/auth.config.ts +0 -83
  282. package/src/lib/auth/auth.gql.ts +0 -62
  283. package/src/lib/auth/auth.types.ts +0 -79
  284. package/src/lib/auth/idle.service.spec.ts +0 -119
  285. package/src/lib/auth/idle.service.ts +0 -208
  286. package/src/lib/auth/idle.types.ts +0 -11
  287. package/src/lib/auth/lbop.service.spec.ts +0 -56
  288. package/src/lib/auth/lbop.service.ts +0 -539
  289. package/src/lib/auth/life-ready-auth.service.spec.ts +0 -70
  290. package/src/lib/auth/life-ready-auth.service.ts +0 -454
  291. package/src/lib/auth/password.service.spec.ts +0 -51
  292. package/src/lib/auth/password.service.ts +0 -438
  293. package/src/lib/auth/register.service.spec.ts +0 -31
  294. package/src/lib/auth/register.service.ts +0 -181
  295. package/src/lib/auth/two-factor.service.spec.ts +0 -21
  296. package/src/lib/auth/two-factor.service.ts +0 -69
  297. package/src/lib/category/category-meta.service.spec.ts +0 -28
  298. package/src/lib/category/category-meta.service.ts +0 -125
  299. package/src/lib/category/category.gql.ts +0 -449
  300. package/src/lib/category/category.service.spec.ts +0 -26
  301. package/src/lib/category/category.service.ts +0 -498
  302. package/src/lib/category/category.types.ts +0 -89
  303. package/src/lib/cryptography/cryptography.types.ts +0 -108
  304. package/src/lib/cryptography/encryption.service.spec.ts +0 -125
  305. package/src/lib/cryptography/encryption.service.ts +0 -243
  306. package/src/lib/cryptography/key-factory.service.spec.ts +0 -15
  307. package/src/lib/cryptography/key-factory.service.ts +0 -303
  308. package/src/lib/cryptography/key-graph.service.spec.ts +0 -16
  309. package/src/lib/cryptography/key-graph.service.ts +0 -354
  310. package/src/lib/cryptography/key-meta.service.spec.ts +0 -40
  311. package/src/lib/cryptography/key-meta.service.ts +0 -254
  312. package/src/lib/cryptography/key.service.spec.ts +0 -16
  313. package/src/lib/cryptography/key.service.ts +0 -154
  314. package/src/lib/cryptography/slip39.service.spec.ts +0 -44
  315. package/src/lib/cryptography/slip39.service.ts +0 -204
  316. package/src/lib/cryptography/web-crypto.service.ts +0 -22
  317. package/src/lib/life-ready.config.ts +0 -127
  318. package/src/lib/life-ready.module.ts +0 -81
  319. package/src/lib/plan/plan.gql.ts +0 -133
  320. package/src/lib/plan/plan.service.spec.ts +0 -294
  321. package/src/lib/plan/plan.service.ts +0 -198
  322. package/src/lib/plan/plan.types.ts +0 -37
  323. package/src/lib/record/record-attachment.service.spec.ts +0 -31
  324. package/src/lib/record/record-attachment.service.ts +0 -101
  325. package/src/lib/record/record.gql.ts +0 -192
  326. package/src/lib/record/record.service.spec.ts +0 -598
  327. package/src/lib/record/record.service.ts +0 -236
  328. package/src/lib/record/record.types.ts +0 -86
  329. package/src/lib/record-type/record-type.service.spec.ts +0 -16
  330. package/src/lib/record-type/record-type.service.ts +0 -71
  331. package/src/lib/record-type/record-type.types.ts +0 -58
  332. package/src/lib/scenario/approvals/scenario-approval.gql.ts +0 -112
  333. package/src/lib/scenario/approvals/scenario-approval.types.ts +0 -85
  334. package/src/lib/scenario/approvals/scenario-approver.service.spec.ts +0 -16
  335. package/src/lib/scenario/approvals/scenario-approver.service.ts +0 -422
  336. package/src/lib/scenario/claimants/scenario-claimant.gql.ts +0 -56
  337. package/src/lib/scenario/claimants/scenario-claimant.service.spec.ts +0 -16
  338. package/src/lib/scenario/claimants/scenario-claimant.service.ts +0 -100
  339. package/src/lib/scenario/claimants/scenario-claimant.types.ts +0 -21
  340. package/src/lib/scenario/receivers/scenario-receiver.gql.ts +0 -157
  341. package/src/lib/scenario/receivers/scenario-receiver.service.spec.ts +0 -16
  342. package/src/lib/scenario/receivers/scenario-receiver.service.ts +0 -278
  343. package/src/lib/scenario/receivers/scenario-receiver.types.ts +0 -66
  344. package/src/lib/scenario/scenario-setup.service.spec.ts +0 -22
  345. package/src/lib/scenario/scenario-setup.service.ts +0 -369
  346. package/src/lib/scenario/scenario.gql.ts +0 -404
  347. package/src/lib/scenario/scenario.service.spec.ts +0 -1586
  348. package/src/lib/scenario/scenario.service.ts +0 -811
  349. package/src/lib/scenario/scenario.types.ts +0 -258
  350. package/src/lib/search/search.gql.ts +0 -62
  351. package/src/lib/search/search.service.spec.ts +0 -57
  352. package/src/lib/search/search.service.ts +0 -174
  353. package/src/lib/search/search.types.ts +0 -24
  354. package/src/lib/trusted-parties/tp-password-reset-request.service.ts +0 -140
  355. package/src/lib/trusted-parties/tp-password-reset-user.service.ts +0 -359
  356. package/src/lib/trusted-parties/tp-password-reset.gql.ts +0 -453
  357. package/src/lib/trusted-parties/tp-password-reset.service.spec.ts +0 -602
  358. package/src/lib/trusted-parties/tp-password-reset.service.ts +0 -482
  359. package/src/lib/trusted-parties/trusted-party.gql.ts +0 -159
  360. package/src/lib/trusted-parties/trusted-party.service.spec.ts +0 -1008
  361. package/src/lib/trusted-parties/trusted-party.service.ts +0 -394
  362. package/src/lib/trusted-parties/trusted-party.types.ts +0 -119
  363. package/src/lib/trusted-parties/trusted-party2.gql.ts +0 -165
  364. package/src/lib/trusted-parties/trusted-party2.service.spec.ts +0 -1782
  365. package/src/lib/trusted-parties/trusted-party2.service.ts +0 -272
  366. package/src/lib/users/profile-details.service.spec.ts +0 -45
  367. package/src/lib/users/profile-details.service.ts +0 -278
  368. package/src/lib/users/profile.gql.ts +0 -108
  369. package/src/lib/users/profile.service.spec.ts +0 -97
  370. package/src/lib/users/profile.service.ts +0 -224
  371. package/src/lib/users/profile.types.ts +0 -101
  372. package/src/lib/users/user.gql.ts +0 -69
  373. package/src/lib/users/user.service.spec.ts +0 -161
  374. package/src/lib/users/user.service.ts +0 -72
  375. package/src/lib/users/user.types.ts +0 -27
  376. package/src/test.ts +0 -21
  377. package/tsconfig.lib.json +0 -21
  378. package/tsconfig.lib.prod.json +0 -6
  379. package/tsconfig.spec.json +0 -10
  380. package/tslint.json +0 -17
@@ -1,731 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import { JWK } from 'node-jose';
3
- import { LifeReadyAuthService } from '../auth/life-ready-auth.service';
4
- import { KeyGraphResponse } from '../cryptography/cryptography.types';
5
- import {
6
- EncryptionService,
7
- JoseSerialization,
8
- } from '../cryptography/encryption.service';
9
- import { KeyService } from '../cryptography/key.service';
10
- import { LrCodeMismatchException } from '../_common/exceptions';
11
- import { UserService } from './../users/user.service';
12
- import {
13
- CompleteOtkMutation,
14
- CurrentUserSharedKeyQuery,
15
- InitiateOtkMutation,
16
- KeyExchangeQuery,
17
- KeyExchangesQuery,
18
- KeyExchangeTokenQuery,
19
- RespondOtkMutation,
20
- } from './key-exchange.gql';
21
- import {
22
- CompleteOtk,
23
- DecryptedKeyExchange,
24
- DecryptedOtk,
25
- GetKeyExchangeListOptions,
26
- GetKeyExchangeOptions,
27
- InitiateOtkInput,
28
- KeyExchange,
29
- OtkState,
30
- PlainInitiatorOneTimePbkCipher,
31
- PlainInitiatorRootKeyCipher,
32
- PlainOtKeyCipher,
33
- PlainResponderPbkCipher,
34
- RespondOtk,
35
- RespondOtkInput,
36
- UserSharedKey,
37
- } from './key-exchange.types';
38
- import { LrApolloService } from './lr-apollo.service';
39
- import { KeyFactoryService as KFS } from '../cryptography/key-factory.service';
40
- // Ref: https://stackoverflow.com/questions/59735280/angular-8-moment-error-cannot-call-a-namespace-moment
41
- import * as moment_ from 'moment';
42
- const moment = moment_;
43
-
44
- @Injectable({
45
- providedIn: 'root',
46
- })
47
- export class KeyExchangeService {
48
- private readonly CLIENT_NONCE_LENGTH = 32;
49
-
50
- constructor(
51
- private keyFactory: KFS,
52
- private keyService: KeyService,
53
- private lrApollo: LrApolloService,
54
- private encryptionService: EncryptionService,
55
- private authService: LifeReadyAuthService,
56
- private userService: UserService
57
- ) {}
58
-
59
- public async getKeyExchangeList(
60
- input: GetKeyExchangeListOptions = {}
61
- ): Promise<any> {
62
- const { keyExchanges } = await this.lrApollo.query<{
63
- keyExchanges: any;
64
- keyGraph: KeyGraphResponse;
65
- }>({
66
- query: KeyExchangesQuery,
67
- variables: {
68
- ...input,
69
- },
70
- });
71
- return keyExchanges;
72
- }
73
-
74
- /**
75
- * @param id If the current user can responder the key exchange if they are either the initiator or the receiver.
76
- * @param token If not signed in, or not the initiator or responder, 'token' must be given.
77
- * @param otKeyK Is the raw one-time key (string). If the responder is explicitly specified at time of initiation, then
78
- * it's possible to have the otKey wrapped by the public key of the responder. In which case, the otKeyK is not needed.
79
- */
80
- public async getKeyExchange(
81
- id: string,
82
- { otKeyK, token }: GetKeyExchangeOptions = {}
83
- ): Promise<DecryptedKeyExchange> {
84
- const { keyExchange } = await this.lrApollo.query<{
85
- keyExchange: KeyExchange;
86
- keyGraph: KeyGraphResponse;
87
- }>({
88
- query: token ? KeyExchangeTokenQuery : KeyExchangeQuery,
89
- variables: {
90
- id,
91
- token,
92
- },
93
- });
94
- return await this.decryptKeyExchange(keyExchange, otKeyK);
95
- }
96
-
97
- private async decryptResponseCipher(
98
- otKey: JWK.Key,
99
- otPrk: JWK.Key,
100
- content: any
101
- ): Promise<PlainInitiatorOneTimePbkCipher> {
102
- // The response could be wrapped by the OtK as well as we the OtPrk
103
- try {
104
- content = await this.encryptionService.decrypt(otKey, content);
105
- } catch (error) {
106
- if (error.message !== 'no key found') {
107
- throw error;
108
- }
109
- // Do nothing to support older versions where message is not wrapped with otk.
110
- }
111
-
112
- // The Prk is single-use and only used to send information from the responder back to the initiator.
113
- return await this.encryptionService.decrypt(otPrk, content);
114
- }
115
-
116
- public async decryptKeyExchange(
117
- keyExchange: KeyExchange,
118
- otKeyK?: string
119
- ): Promise<DecryptedKeyExchange> {
120
- if (keyExchange.isInitiator) {
121
- const rootKey = await this.keyService.getCurrentRootKey();
122
- // Decrypt using the root key to get the Prk
123
- const plainInitiatorRootKeyCipher = ((await this.encryptionService.decrypt(
124
- rootKey.jwk,
125
- keyExchange.initiatorRootKeyCipher
126
- )) as unknown) as PlainInitiatorRootKeyCipher;
127
-
128
- const plainInitiatorOneTimePbkCipher = keyExchange.otk
129
- .initiatorOneTimePbkCipher
130
- ? await this.decryptResponseCipher(
131
- await KFS.asKey(plainInitiatorRootKeyCipher.otKey),
132
- await KFS.asKey(plainInitiatorRootKeyCipher.oneTimePrk),
133
- keyExchange.otk.initiatorOneTimePbkCipher
134
- )
135
- : null;
136
-
137
- const responder =
138
- plainInitiatorOneTimePbkCipher &&
139
- plainInitiatorOneTimePbkCipher.responder;
140
- const initiator =
141
- plainInitiatorRootKeyCipher && plainInitiatorRootKeyCipher.initiator;
142
-
143
- return {
144
- ...keyExchange,
145
- message: responder ? responder.message : null,
146
- contactCard:
147
- responder && responder.contactCard
148
- ? responder.contactCard.plainSharedCipherDataJson
149
- : null,
150
- myContactCard:
151
- initiator && initiator.contactCard
152
- ? initiator.contactCard.plainSharedCipherDataJson
153
- : null,
154
- myMessage: initiator && initiator.message,
155
- };
156
- } else {
157
- const decryptedOtk = await this.decryptOtk(keyExchange, otKeyK);
158
-
159
- const initiator = decryptedOtk && decryptedOtk.plainOtKeyCipher.initiator;
160
-
161
- return {
162
- ...keyExchange,
163
- decryptedOtk,
164
- message: initiator && initiator.message,
165
- contactCard:
166
- initiator &&
167
- initiator.contactCard &&
168
- initiator.contactCard.plainSharedCipherDataJson,
169
- };
170
- }
171
- }
172
-
173
- private async decryptOtk(
174
- keyExchange: KeyExchange,
175
- otKeyK?: string
176
- ): Promise<DecryptedOtk> {
177
- const otKey = await this.getOtKey(keyExchange, otKeyK);
178
-
179
- return otKey && keyExchange.otk.otKeyCipher
180
- ? {
181
- plainOtKeyCipher: await this.encryptionService.decrypt(
182
- otKey,
183
- keyExchange.otk.otKeyCipher
184
- ),
185
- otKey,
186
- }
187
- : null;
188
- }
189
-
190
- private async getOtKey(
191
- keyExchange: KeyExchange,
192
- otKeyK?: string
193
- ): Promise<JWK.Key> {
194
- if (otKeyK) {
195
- return await KFS.asKey({
196
- ...JSON.parse(keyExchange.otk.otKeyParams),
197
- k: otKeyK,
198
- });
199
- } else if (
200
- keyExchange.otk.state === OtkState.OTK_INITIATED &&
201
- !keyExchange.isInitiator &&
202
- keyExchange.otk.responderPbkCipher
203
- ) {
204
- // Assuming existing user getting invited where OTK is wrapped in responder's public key.
205
- const prk = await this.keyService.getCurrentPxk();
206
- const decryptedCipher: any = await this.encryptionService.decrypt(
207
- prk.jwk,
208
- JSON.parse(keyExchange.otk.responderPbkCipher),
209
- {
210
- serializations: [JoseSerialization.COMPACT],
211
- }
212
- );
213
- if (decryptedCipher.otKey) {
214
- return await KFS.asKey(decryptedCipher.otKey);
215
- }
216
- }
217
- return null;
218
- }
219
-
220
- async initiateOtk({
221
- message,
222
- email,
223
- contactCard,
224
- upgrade,
225
- }: InitiateOtkInput): Promise<{ keyExchange: KeyExchange; otKeyK: string }> {
226
- const otKey = await this.keyFactory.createKey();
227
- const nonce = this.keyFactory.randomString(this.CLIENT_NONCE_LENGTH);
228
- const user = await this.authService.getUser();
229
-
230
- // New PKC key for encryption. This key is used only once when the responder sends
231
- // back their signing public key.
232
- const initiatorOneTimePrk = await this.keyFactory.createPkcKey();
233
-
234
- // Option 1: New PKC key for signing
235
- // const initiatorSigPrk = await this.keyService.createPkcSignKey();
236
-
237
- // Option 2: Use the user's global signing key.
238
- // This key is used to prove the initiator's identity.
239
- const initiatorPrk = await this.keyService.getCurrentPxk();
240
- const initiatorSigPrk = await this.keyService.getCurrentSigPxk();
241
-
242
- let initiatorPlainDataSig: string = null;
243
-
244
- if (contactCard && contactCard.ownerPlainData) {
245
- initiatorPlainDataSig = JSON.stringify(
246
- await this.encryptionService.sign(
247
- initiatorSigPrk.jwk,
248
- contactCard.ownerPlainData
249
- )
250
- );
251
- }
252
-
253
- const initiator = {
254
- message,
255
- contactCard: contactCard
256
- ? {
257
- plainSharedCipherDataJson: contactCard.plainSharedCipherDataJson,
258
- }
259
- : null,
260
- };
261
-
262
- // Content to be encrypted using the OTK.
263
- const plainOtKeyCipher: PlainOtKeyCipher = {
264
- nonce,
265
- initiator: {
266
- ...initiator,
267
- oneTimePbk: initiatorOneTimePrk.toJSON(), // onetime public encryption key responder use to send data back to initiator
268
- pbk: initiatorPrk.jwk.toJSON(), // public encryption key
269
- sigPbk: initiatorSigPrk.jwk.toJSON(), // public signing key
270
- profile: {
271
- username: user.username,
272
- },
273
- },
274
- };
275
-
276
- const otKeyCipher = await this.encryptionService.encrypt(
277
- otKey,
278
- plainOtKeyCipher
279
- );
280
-
281
- // Content to be encrypted using the initiator's root key.
282
- const plainInitiatorRootKeyCipher: PlainInitiatorRootKeyCipher = {
283
- nonce,
284
- oneTimePrk: initiatorOneTimePrk.toJSON(true),
285
- // Should not need to keep this encrypted since we are using the global signing key.
286
- // sigPrk: initiatorSigPrk.toJSON(true),
287
-
288
- // Save it in case the initiator want to decode the otKeyCipher.
289
- // Since the otKey is only used once, and that otKeyCipher contains only
290
- // the public key of the initiator, it's safe just leave the otKey stored here.
291
- otKey: otKey.toJSON(true),
292
- // These should be storing information such as how the fields of the shared contact card is
293
- // derived from the master contact card.
294
- initiatorContactCard: contactCard,
295
- initiator,
296
- };
297
-
298
- const rootKey = await this.keyService.getCurrentRootKey();
299
- const initiatorRootKeyCipher = await this.encryptionService.encrypt(
300
- rootKey.jwk,
301
- plainInitiatorRootKeyCipher
302
- );
303
-
304
- // The raw OTK
305
- const otKeyK: string = (otKey.toJSON(true) as any).k;
306
-
307
- // API call
308
- const { initiateKeyExchangeOtk } = await this.lrApollo.mutate<any>({
309
- mutation: InitiateOtkMutation,
310
- variables: {
311
- input: {
312
- // These will be stored on the server
313
- initiatorRootKeyCipher: JSON.stringify(initiatorRootKeyCipher),
314
- initiatorPxkId: initiatorPrk.id,
315
- initiatorSigPxkId: initiatorSigPrk.id,
316
- // These will be sent to the responder
317
- otKeyParams: JSON.stringify(otKey.toJSON()),
318
- otKeyCipher: JSON.stringify(otKeyCipher),
319
- sendEmail: email
320
- ? {
321
- email,
322
- rawOtKey: otKeyK,
323
- }
324
- : null,
325
- createTp: true,
326
- initiatorPlainDataSig,
327
- upgrade,
328
- },
329
- },
330
- });
331
- return { keyExchange: initiateKeyExchangeOtk.keyExchange, otKeyK };
332
- }
333
-
334
- async respondOtk({
335
- id,
336
- token,
337
- decryptedOtk,
338
- message,
339
- initiatorContactCard,
340
- responderContactCard: sentContactCard,
341
- }: RespondOtkInput): Promise<RespondOtk> {
342
- const user = await this.authService.getUser();
343
- const rootKey = await this.keyService.getCurrentRootKey();
344
-
345
- const masterKeyId = this.keyService.getCurrentMasterKey().id;
346
- const masterKey = await this.keyService.getCurrentMasterKey();
347
-
348
- const sharedKey = await this.keyFactory.createKey();
349
- const mkSharedKey = await this.keyFactory.createKey();
350
-
351
- const rkWrappedSharedKey = await this.encryptionService.encrypt(
352
- rootKey.jwk,
353
- sharedKey.toJSON(true)
354
- );
355
- const mkWrappedMkSharedKey = await this.encryptionService.encrypt(
356
- masterKey.jwk,
357
- mkSharedKey.toJSON(true)
358
- );
359
-
360
- const initiatorOneTimePbk = await KFS.asKey(
361
- decryptedOtk.plainOtKeyCipher.initiator.oneTimePbk
362
- );
363
-
364
- const initiatorPbk = await KFS.asKey(
365
- decryptedOtk.plainOtKeyCipher.initiator.pbk
366
- );
367
- const initiatorSigPbk = await KFS.asKey(
368
- decryptedOtk.plainOtKeyCipher.initiator.sigPbk
369
- );
370
-
371
- // Option 1: Using new Prk for each TP pair
372
- // Create a new public signing key for the responder.
373
- // const responderSigPrk = await this.keyService.createPkcSignKey()
374
- // const rkWrappedResponderSigPrk = await this.encrypt(rootKey, responderSigPrk.toJSON(true));
375
-
376
- // Option 2: Responder already has a signing Prk
377
- const responderPrk = await this.keyService.getCurrentPxk();
378
- const responderSigPrk = await this.keyService.getCurrentSigPxk();
379
-
380
- const signedInitiatorPbk = await this.encryptionService.sign(
381
- responderSigPrk.jwk,
382
- initiatorPbk.toJSON()
383
- );
384
- const signedInitiatorSigPbk = await this.encryptionService.sign(
385
- responderSigPrk.jwk,
386
- initiatorSigPbk.toJSON()
387
- );
388
-
389
- const plainInitiatorOneTimePbkCipher: PlainInitiatorOneTimePbkCipher = {
390
- nonce: decryptedOtk.plainOtKeyCipher.nonce,
391
- sharedKey: sharedKey.toJSON(true),
392
- mkSharedKey: mkSharedKey.toJSON(true),
393
- responder: {
394
- pbk: responderPrk.jwk.toJSON(), // public key
395
- sigPbk: responderSigPrk.jwk.toJSON(), // public key
396
- profile: {
397
- username: user.username,
398
- },
399
- message,
400
- },
401
- };
402
-
403
- let receivedCardInput;
404
- if (decryptedOtk.plainOtKeyCipher.initiator.contactCard) {
405
- // Set the info about the initiator to be the ones sent by the initiator. We need th responder to do the encryption here
406
- // because the initiator does not have the shared key yet, and we want the responder to have a functional contact card after
407
- // this exchange. The initiator can double check the contact details are correct and sign it when it completes the exchange.
408
- const plainSharedCipherDataJson =
409
- decryptedOtk.plainOtKeyCipher.initiator.contactCard
410
- .plainSharedCipherDataJson;
411
-
412
- // Create keys
413
- const receiverKey = await this.keyFactory.createKey();
414
- const ccSharedKey = await this.keyFactory.createKey();
415
- const sigPxk = await this.keyService.getCurrentSigPxk();
416
-
417
- receivedCardInput = {
418
- receiverWrappedKey: JSON.stringify(
419
- await this.encryptionService.encrypt(
420
- rootKey.jwk,
421
- receiverKey.toJSON(true)
422
- )
423
- ),
424
- receiverWrappingKeyId: rootKey.id,
425
- receiverCipherData: initiatorContactCard
426
- ? JSON.stringify(
427
- await this.encryptionService.encrypt(
428
- receiverKey,
429
- initiatorContactCard.plainReceiverCipherDataJson
430
- )
431
- )
432
- : '',
433
- sharedWrappedKey: JSON.stringify(
434
- await this.encryptionService.encrypt(
435
- sharedKey,
436
- ccSharedKey.toJSON(true)
437
- )
438
- ),
439
- };
440
-
441
- const sharedCipherData = await this.encryptionService.encrypt(
442
- ccSharedKey,
443
- plainSharedCipherDataJson
444
- );
445
- receivedCardInput.sharedCipherDataSig = JSON.stringify(
446
- await this.encryptionService.sign(sigPxk.jwk, sharedCipherData)
447
- );
448
- receivedCardInput.sigPxkId = sigPxk.id;
449
-
450
- plainInitiatorOneTimePbkCipher.responder.contactCard = {
451
- ...plainInitiatorOneTimePbkCipher.responder.contactCard,
452
- sharedCipherKey: ccSharedKey.toJSON(true),
453
- };
454
- }
455
-
456
- let sentCardInput;
457
- if (sentContactCard) {
458
- // Create keys
459
- const ownerKey = await this.keyFactory.createKey();
460
- const ccSharedKey = await this.keyFactory.createKey();
461
- const sigPxk = await this.keyService.getCurrentSigPxk();
462
-
463
- sentCardInput = {
464
- ownerWrappedKey: JSON.stringify(
465
- await this.encryptionService.encrypt(
466
- rootKey.jwk,
467
- ownerKey.toJSON(true)
468
- )
469
- ),
470
- ownerWrappingKeyId: rootKey.id,
471
- ownerCipherData: sentContactCard.plainOwnerCipherDataJson
472
- ? JSON.stringify(
473
- await this.encryptionService.encrypt(
474
- ownerKey,
475
- sentContactCard.plainOwnerCipherDataJson
476
- )
477
- )
478
- : '',
479
-
480
- sharedWrappedKey: JSON.stringify(
481
- await this.encryptionService.encrypt(
482
- sharedKey,
483
- ccSharedKey.toJSON(true)
484
- )
485
- ),
486
- };
487
-
488
- const sharedCipherData = await this.encryptionService.encrypt(
489
- ccSharedKey,
490
- sentContactCard.plainSharedCipherDataJson
491
- );
492
- sentCardInput.sharedCipherDataSig = JSON.stringify(
493
- await this.encryptionService.sign(sigPxk.jwk, sharedCipherData)
494
- );
495
- sentCardInput.sigPxkId = sigPxk.id;
496
-
497
- if (sentContactCard.ownerPlainData) {
498
- sentCardInput.ownerPlainDataSig = JSON.stringify(
499
- await this.encryptionService.sign(
500
- responderSigPrk.jwk,
501
- sentContactCard.ownerPlainData
502
- )
503
- );
504
- }
505
-
506
- // Contact card info readable by the initiator
507
- plainInitiatorOneTimePbkCipher.responder.contactCard = {
508
- ...plainInitiatorOneTimePbkCipher.responder.contactCard,
509
- plainSharedCipherDataJson: sentContactCard.plainSharedCipherDataJson,
510
- };
511
- }
512
-
513
- // Encrypt with one-time public key
514
- let initiatorOneTimePbkCipher = await this.encryptionService.encrypt(
515
- initiatorOneTimePbk,
516
- plainInitiatorOneTimePbkCipher
517
- );
518
-
519
- // Encrypt with the otk again to keep use of asymmetric keys to a minimum.
520
- initiatorOneTimePbkCipher = await this.encryptionService.encrypt(
521
- decryptedOtk.otKey,
522
- initiatorOneTimePbkCipher
523
- );
524
-
525
- const { respondKeyExchangeOtk } = await this.lrApollo.mutate<any>({
526
- mutation: RespondOtkMutation,
527
- variables: {
528
- input: {
529
- keyExchangeId: id,
530
- keyExchangeToken: token,
531
- rootKeyId: rootKey.id,
532
- masterKeyId,
533
- // These will be stored on the server
534
- responderPxkId: responderPrk.id,
535
- responderSigPxkId: responderSigPrk.id,
536
- signedInitiatorPbk: JSON.stringify(signedInitiatorPbk),
537
- signedInitiatorSigPbk: JSON.stringify(signedInitiatorSigPbk),
538
- // rkWrappedInitiatorSigPbk: JSON.stringify(rkWrappedInitiatorSigPbk),
539
-
540
- // Option 1: Using new Prk for each TP pair
541
- // rkWrappedResponderSigPrk: JSON.stringify(rkWrappedResponderSigPrk),
542
- rkWrappedSharedKey: JSON.stringify(rkWrappedSharedKey),
543
- mkWrappedMkSharedKey: JSON.stringify(mkWrappedMkSharedKey),
544
- // These will be sent to the initiator
545
- initiatorOneTimePbkCipher: JSON.stringify(initiatorOneTimePbkCipher),
546
- initiatorContactCard: receivedCardInput,
547
- responderContactCard: sentCardInput,
548
- },
549
- },
550
- });
551
-
552
- return {
553
- keyExchange: respondKeyExchangeOtk.keyExchange,
554
- userSharedKey: respondKeyExchangeOtk.userSharedKey,
555
- tp: respondKeyExchangeOtk.tp,
556
- };
557
- }
558
-
559
- async completeOtk(
560
- keyExchangeId: string,
561
- initiatorRootKeyCipher: string,
562
- initiatorOneTimePbkCipher: string,
563
- responderContactCard?: string
564
- ): Promise<CompleteOtk> {
565
- const rootKey = await this.keyService.getCurrentRootKey();
566
- const masterKey = await this.keyService.getCurrentMasterKey();
567
-
568
- // Decrypt using the root key to get the Prk
569
- const plainInitiatorRootKeyCipher = ((await this.encryptionService.decrypt(
570
- rootKey.jwk,
571
- initiatorRootKeyCipher
572
- )) as unknown) as PlainInitiatorRootKeyCipher;
573
-
574
- // The Prk is single-use and only used to send information from the responder back to the initiator.
575
- const plainInitiatorOneTimePbkCipher = await this.decryptResponseCipher(
576
- await KFS.asKey(plainInitiatorRootKeyCipher.otKey),
577
- await KFS.asKey(plainInitiatorRootKeyCipher.oneTimePrk),
578
- initiatorOneTimePbkCipher
579
- );
580
-
581
- // Check the nonce match to ensure the responder was the one holding the OTK
582
- if (
583
- plainInitiatorRootKeyCipher.nonce !== plainInitiatorOneTimePbkCipher.nonce
584
- ) {
585
- throw new LrCodeMismatchException(
586
- 'The nonce returned by responder does not match with the one created by the initiator.'
587
- );
588
- }
589
-
590
- // Option 1: Assuming the signing key is unique between users.
591
- // const initiatorSigPrk = await KFS.asKey(ke.plainInitiatorRootKeyCipher.sigPrk);
592
- // const rkWrappedInitiatorSigPrk = await this.encrypt(rootKey, initiatorSigPrk.toJSON(true));
593
-
594
- // Option 2: Use the user's global signing key.
595
- // In this case the initiatorSigPrk is already a part of the key graph.
596
- // So there's nothing to do here.
597
-
598
- // Protected the signing public key of the responder.
599
- const initiatorSigPrk = await this.keyService.getCurrentSigPxk();
600
- const responderSigPbk = await KFS.asKey(
601
- plainInitiatorOneTimePbkCipher.responder.sigPbk
602
- );
603
- const responderPbk = await KFS.asKey(
604
- plainInitiatorOneTimePbkCipher.responder.pbk
605
- );
606
-
607
- const signedResponderPbk = await this.encryptionService.sign(
608
- initiatorSigPrk.jwk,
609
- responderPbk.toJSON()
610
- );
611
- const signedResponderSigPbk = await this.encryptionService.sign(
612
- initiatorSigPrk.jwk,
613
- responderSigPbk.toJSON()
614
- );
615
-
616
- const sharedKey = await KFS.asKey(plainInitiatorOneTimePbkCipher.sharedKey);
617
- const rkWrappedSharedKey = await this.encryptionService.encrypt(
618
- rootKey.jwk,
619
- sharedKey.toJSON(true)
620
- );
621
-
622
- const mkSharedKey = await KFS.asKey(
623
- plainInitiatorOneTimePbkCipher.mkSharedKey
624
- );
625
- const mkWrappedMkSharedKey = await this.encryptionService.encrypt(
626
- masterKey.jwk,
627
- mkSharedKey.toJSON(true)
628
- );
629
-
630
- let responderContactCardCipherInput;
631
- if (responderContactCard) {
632
- // Create key
633
- const receiverKey = await this.keyFactory.createKey();
634
-
635
- responderContactCardCipherInput = {
636
- receiverWrappedKey: JSON.stringify(
637
- await this.encryptionService.encrypt(
638
- rootKey.jwk,
639
- receiverKey.toJSON(true)
640
- )
641
- ),
642
- receiverWrappingKeyId: rootKey.id,
643
- receiverCipherData: JSON.stringify(
644
- await this.encryptionService.encrypt(
645
- receiverKey,
646
- responderContactCard
647
- )
648
- ),
649
- };
650
- }
651
-
652
- // Get the data needed from the initiator's cipher data.
653
- let initiatorContactCardCipherInput;
654
- let initiatorContactCardSharedCipherInput;
655
- if (plainInitiatorRootKeyCipher.initiatorContactCard) {
656
- const initiatorContactCard =
657
- plainInitiatorRootKeyCipher.initiatorContactCard;
658
- const ownerKey = await this.keyFactory.createKey();
659
- const sharedCipherKey = await KFS.asKey(
660
- plainInitiatorOneTimePbkCipher.responder.contactCard.sharedCipherKey
661
- );
662
-
663
- const ownerWrappedKey = JSON.stringify(
664
- await this.encryptionService.encrypt(rootKey.jwk, ownerKey.toJSON(true))
665
- );
666
- const ownerCipherData = initiatorContactCard.plainOwnerCipherDataJson
667
- ? JSON.stringify(
668
- await this.encryptionService.encrypt(
669
- ownerKey,
670
- initiatorContactCard.plainOwnerCipherDataJson
671
- )
672
- )
673
- : '';
674
-
675
- initiatorContactCardCipherInput = {
676
- ownerWrappedKey,
677
- ownerWrappingKeyId: rootKey.id,
678
- ownerCipherData,
679
- };
680
-
681
- initiatorContactCardSharedCipherInput = {
682
- sigPxkId: initiatorSigPrk.id,
683
- };
684
-
685
- const sharedCipherData = await this.encryptionService.encrypt(
686
- sharedCipherKey,
687
- initiatorContactCard.plainSharedCipherDataJson
688
- );
689
- initiatorContactCardSharedCipherInput.sharedCipherDataSig = JSON.stringify(
690
- await this.encryptionService.sign(initiatorSigPrk.jwk, sharedCipherData)
691
- );
692
- }
693
-
694
- // TODO ideally we update the shared data in the contact card sent to the responder as well since that
695
- // CC was created by the responder.
696
-
697
- const res = await this.lrApollo.mutate<any>({
698
- mutation: CompleteOtkMutation,
699
- variables: {
700
- input: {
701
- keyExchangeId,
702
- rootKeyId: rootKey.id,
703
- masterKeyId: masterKey.id,
704
- initiatorSigPxkId: initiatorSigPrk.id,
705
- signedResponderPbk: JSON.stringify(signedResponderPbk),
706
- signedResponderSigPbk: JSON.stringify(signedResponderSigPbk),
707
- rkWrappedSharedKey: JSON.stringify(rkWrappedSharedKey),
708
- mkWrappedMkSharedKey: JSON.stringify(mkWrappedMkSharedKey),
709
- responderContactCardCipher: responderContactCardCipherInput,
710
- initiatorContactCardCipher: initiatorContactCardCipherInput,
711
- initiatorContactCardSharedCipher: initiatorContactCardSharedCipherInput,
712
- },
713
- },
714
- });
715
- return res.completeKeyExchangeOtk;
716
- }
717
-
718
- public async currentUserSharedKey(input: {
719
- username?: string;
720
- userId?: string;
721
- }): Promise<UserSharedKey> {
722
- const { currentUserSharedKey } = await this.lrApollo.query<any>({
723
- query: CurrentUserSharedKeyQuery,
724
- variables: {
725
- username: input.username,
726
- userId: input.userId,
727
- },
728
- });
729
- return currentUserSharedKey.userSharedKey;
730
- }
731
- }