oro-sdk 2.1.4-dev1.0 → 2.2.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 (63) hide show
  1. package/README.md +26 -34
  2. package/dist/client.d.ts +4 -4
  3. package/dist/helpers/client.d.ts +1 -1
  4. package/dist/helpers/patient-registration.d.ts +1 -1
  5. package/dist/helpers/vault-grants.d.ts +1 -1
  6. package/dist/helpers/workflow.d.ts +1 -1
  7. package/dist/index.d.ts +15 -1
  8. package/dist/models/client.d.ts +1 -1
  9. package/dist/models/error.d.ts +0 -14
  10. package/dist/models/index.d.ts +0 -7
  11. package/dist/oro-sdk.cjs.development.js +313 -2367
  12. package/dist/oro-sdk.cjs.development.js.map +1 -1
  13. package/dist/oro-sdk.cjs.production.min.js +1 -1
  14. package/dist/oro-sdk.cjs.production.min.js.map +1 -1
  15. package/dist/oro-sdk.esm.js +246 -2344
  16. package/dist/oro-sdk.esm.js.map +1 -1
  17. package/dist/sdk-revision/client.d.ts +2 -2
  18. package/dist/services/index.d.ts +0 -9
  19. package/package.json +4 -1
  20. package/src/client.ts +161 -435
  21. package/src/helpers/client.ts +1 -1
  22. package/src/helpers/patient-registration.ts +85 -166
  23. package/src/helpers/vault-grants.ts +1 -1
  24. package/src/helpers/workflow.ts +21 -59
  25. package/src/index.ts +42 -28
  26. package/src/models/client.ts +1 -1
  27. package/src/models/error.ts +6 -13
  28. package/src/models/index.ts +0 -7
  29. package/src/sdk-revision/client.ts +25 -20
  30. package/src/services/external/clinia.ts +1 -1
  31. package/src/services/index.ts +0 -9
  32. package/dist/models/consult.d.ts +0 -102
  33. package/dist/models/diagnosis.d.ts +0 -122
  34. package/dist/models/guard.d.ts +0 -119
  35. package/dist/models/practice.d.ts +0 -353
  36. package/dist/models/shared.d.ts +0 -8
  37. package/dist/models/vault.d.ts +0 -124
  38. package/dist/models/workflow.d.ts +0 -106
  39. package/dist/services/api.d.ts +0 -11
  40. package/dist/services/axios.d.ts +0 -14
  41. package/dist/services/consult.d.ts +0 -54
  42. package/dist/services/diagnosis.d.ts +0 -44
  43. package/dist/services/guard.d.ts +0 -92
  44. package/dist/services/practice.d.ts +0 -100
  45. package/dist/services/teller.d.ts +0 -9
  46. package/dist/services/vault.d.ts +0 -54
  47. package/dist/services/workflow.d.ts +0 -21
  48. package/src/models/consult.ts +0 -110
  49. package/src/models/diagnosis.ts +0 -141
  50. package/src/models/guard.ts +0 -136
  51. package/src/models/practice.ts +0 -411
  52. package/src/models/shared.ts +0 -6
  53. package/src/models/vault.ts +0 -158
  54. package/src/models/workflow.ts +0 -142
  55. package/src/services/api.ts +0 -77
  56. package/src/services/axios.ts +0 -91
  57. package/src/services/consult.ts +0 -265
  58. package/src/services/diagnosis.ts +0 -144
  59. package/src/services/guard.ts +0 -228
  60. package/src/services/practice.ts +0 -537
  61. package/src/services/teller.ts +0 -39
  62. package/src/services/vault.ts +0 -178
  63. package/src/services/workflow.ts +0 -36
package/src/client.ts CHANGED
@@ -1,24 +1,20 @@
1
- import * as OroToolbox from 'oro-toolbox'
2
- import { CryptoRSA } from 'oro-toolbox'
3
- import { registerPatient, sessionStorePrivateKeyName, decryptGrants, decryptConsultLockboxGrants} from './helpers'
4
1
  import {
5
- AssociatedLockboxNotFound,
6
2
  AuthTokenRequest,
7
3
  Consult,
8
4
  ConsultRequest,
5
+ ConsultService,
9
6
  DataCreateResponse,
7
+ DiagnosisService,
10
8
  Document,
11
9
  DocumentType,
12
10
  EncryptedIndexEntry,
13
11
  EncryptedVaultIndex,
14
12
  Grant,
13
+ GuardService,
15
14
  IdentityCreateRequest,
16
15
  IdentityResponse,
17
- IncompleteAuthentication,
18
- IndexBuildError,
19
16
  IndexConsultLockbox,
20
17
  IndexKey,
21
- LocalEncryptedData,
22
18
  LocalizedData,
23
19
  LockboxDataRequest,
24
20
  LockboxGrantRequest,
@@ -27,34 +23,37 @@ import {
27
23
  Meta,
28
24
  Metadata,
29
25
  MetadataCategory,
30
- MissingGrant,
31
- MissingLockbox,
32
- MissingLockboxOwner,
33
26
  PersonalMeta,
34
27
  PopulatedWorkflowData,
35
28
  Practice,
29
+ PracticeService,
36
30
  PreferenceMeta,
37
- RecoveryData,
38
31
  RecoveryMeta,
39
- RegisterPatientOutput,
40
32
  SecretShard,
33
+ TellerService,
41
34
  TokenData,
42
35
  TosAndCpAcceptanceRequest,
43
- UserPreference,
44
36
  Uuid,
45
37
  VaultIndex,
46
- WorkflowData,
47
- } from './models'
48
- import { filterGrantsWithLockboxMetadata, buildLegacyVaultIndex } from './sdk-revision'
49
- import {
50
- ConsultService,
51
- DiagnosisService,
52
- GuardService,
53
- PracticeService,
54
- TellerService,
55
38
  VaultService,
39
+ WorkflowData,
56
40
  WorkflowService,
57
- } from './services'
41
+ } from 'oro-sdk-apis'
42
+ import * as OroToolbox from 'oro-toolbox'
43
+ import { CryptoRSA } from 'oro-toolbox'
44
+ import { decryptConsultLockboxGrants, decryptGrants, registerPatient, sessionStorePrivateKeyName } from './helpers'
45
+ import {
46
+ AssociatedLockboxNotFound,
47
+ IncompleteAuthentication,
48
+ LocalEncryptedData,
49
+ MissingGrant,
50
+ MissingLockbox,
51
+ MissingLockboxOwner,
52
+ RecoveryData,
53
+ RegisterPatientOutput,
54
+ UserPreference,
55
+ } from './models'
56
+ import { buildLegacyVaultIndex, filterGrantsWithLockboxMetadata } from './sdk-revision'
58
57
 
59
58
  export class OroClient {
60
59
  private rsa?: CryptoRSA
@@ -84,13 +83,13 @@ export class OroClient {
84
83
  private authenticationCallback?: (err: Error) => void
85
84
  ) {}
86
85
 
87
- /**
86
+ /**
88
87
  * clears the vaultIndex and cached metadata grants
89
- */
88
+ */
90
89
  public async cleanIndex() {
91
90
  this.vaultIndex = undefined
92
91
  this.cachedMetadataGrants = {}
93
- this.cachedManifest = {}
92
+ this.cachedManifest = {}
94
93
  }
95
94
 
96
95
  /**
@@ -115,16 +114,10 @@ export class OroClient {
115
114
  this.rsa = new CryptoRSA()
116
115
  const privateKey = this.rsa.private()
117
116
 
118
- const symmetricEncryptor = this.toolbox.CryptoChaCha.fromPassphrase(
119
- password
120
- )
121
- const recoveryPassword = symmetricEncryptor.bytesEncryptToBase64Payload(
122
- privateKey
123
- )
117
+ const symmetricEncryptor = this.toolbox.CryptoChaCha.fromPassphrase(password)
118
+ const recoveryPassword = symmetricEncryptor.bytesEncryptToBase64Payload(privateKey)
124
119
 
125
- const hashedPassword = this.toolbox.hashStringToBase64(
126
- this.toolbox.hashStringToBase64(password)
127
- )
120
+ const hashedPassword = this.toolbox.hashStringToBase64(this.toolbox.hashStringToBase64(password))
128
121
 
129
122
  const signupRequest: IdentityCreateRequest = {
130
123
  practiceUuid: practice.uuid,
@@ -141,9 +134,7 @@ export class OroClient {
141
134
 
142
135
  if (identity.recoveryLogin) {
143
136
  //Ensure we can recover from a page reload
144
- let symetricEncryptor = this.toolbox.CryptoChaCha.fromPassphrase(
145
- identity.recoveryLogin
146
- )
137
+ let symetricEncryptor = this.toolbox.CryptoChaCha.fromPassphrase(identity.recoveryLogin)
147
138
  sessionStorage.setItem(
148
139
  sessionStorePrivateKeyName(identity.id),
149
140
  symetricEncryptor.bytesEncryptToBase64Payload(privateKey)
@@ -176,15 +167,8 @@ export class OroClient {
176
167
  * @param otp
177
168
  * @returns the user identity
178
169
  */
179
- public async signIn(
180
- practiceUuid: Uuid,
181
- email: string,
182
- password: string,
183
- otp?: string
184
- ): Promise<IdentityResponse> {
185
- const hashedPassword = this.toolbox.hashStringToBase64(
186
- this.toolbox.hashStringToBase64(password)
187
- )
170
+ public async signIn(practiceUuid: Uuid, email: string, password: string, otp?: string): Promise<IdentityResponse> {
171
+ const hashedPassword = this.toolbox.hashStringToBase64(this.toolbox.hashStringToBase64(password))
188
172
  const tokenRequest: AuthTokenRequest = {
189
173
  practiceUuid,
190
174
  email: email.toLowerCase(),
@@ -206,20 +190,13 @@ export class OroClient {
206
190
  */
207
191
  public async resumeSession() {
208
192
  const id = (await this.guardClient.whoAmI()).sub
209
- const recoveryPayload = sessionStorage.getItem(
210
- sessionStorePrivateKeyName(id)
211
- )
212
- const recoveryKey = (await this.guardClient.identityGet(id))
213
- .recoveryLogin
193
+ const recoveryPayload = sessionStorage.getItem(sessionStorePrivateKeyName(id))
194
+ const recoveryKey = (await this.guardClient.identityGet(id)).recoveryLogin
214
195
 
215
196
  if (!recoveryKey || !recoveryPayload) throw IncompleteAuthentication
216
197
 
217
- const symmetricDecryptor = this.toolbox.CryptoChaCha.fromPassphrase(
218
- recoveryKey
219
- )
220
- let privateKey = symmetricDecryptor.base64PayloadDecryptToBytes(
221
- recoveryPayload
222
- )
198
+ const symmetricDecryptor = this.toolbox.CryptoChaCha.fromPassphrase(recoveryKey)
199
+ let privateKey = symmetricDecryptor.base64PayloadDecryptToBytes(recoveryPayload)
223
200
  this.rsa = this.toolbox.CryptoRSA.fromKey(privateKey)
224
201
  }
225
202
 
@@ -242,9 +219,7 @@ export class OroClient {
242
219
  const chaChaKey = new this.toolbox.CryptoChaCha()
243
220
 
244
221
  const encryptedData = chaChaKey.jsonEncryptToBase64Payload(value)
245
- const encryptedKey = this.toolbox.encodeToBase64(
246
- this.rsa.encryptToBytes(chaChaKey.key())
247
- )
222
+ const encryptedKey = this.toolbox.encodeToBase64(this.rsa.encryptToBytes(chaChaKey.key()))
248
223
 
249
224
  return { encryptedData, encryptedKey }
250
225
  }
@@ -256,10 +231,7 @@ export class OroClient {
256
231
  * @throws IncompleteAuthentication if rsa is not set
257
232
  * @calls authenticationCallback if rsa is not set
258
233
  */
259
- public localDecryptJsonPayload({
260
- encryptedKey,
261
- encryptedData,
262
- }: LocalEncryptedData): any {
234
+ public localDecryptJsonPayload({ encryptedKey, encryptedData }: LocalEncryptedData): any {
263
235
  if (!this.rsa) {
264
236
  if (this.authenticationCallback) {
265
237
  this.authenticationCallback(new IncompleteAuthentication())
@@ -269,9 +241,7 @@ export class OroClient {
269
241
  }
270
242
 
271
243
  const chaChaKey = this.rsa.base64DecryptToBytes(encryptedKey)
272
- const decryptedData = this.toolbox.CryptoChaCha.fromKey(
273
- chaChaKey
274
- ).base64PayloadDecryptToJson(encryptedData)
244
+ const decryptedData = this.toolbox.CryptoChaCha.fromKey(chaChaKey).base64PayloadDecryptToJson(encryptedData)
275
245
 
276
246
  return decryptedData
277
247
  }
@@ -316,14 +286,7 @@ export class OroClient {
316
286
  }
317
287
  ): Promise<RegisterPatientOutput> {
318
288
  if (!this.rsa) throw IncompleteAuthentication
319
- return registerPatient(
320
- patientUuid,
321
- consult,
322
- workflow,
323
- this,
324
- this.toolbox.uuid(),
325
- recoveryQA
326
- )
289
+ return registerPatient(patientUuid, consult, workflow, this, this.toolbox.uuid(), recoveryQA)
327
290
  }
328
291
 
329
292
  /**
@@ -337,8 +300,7 @@ export class OroClient {
337
300
  * @returns the latest vault index
338
301
  */
339
302
  public async buildVaultIndex(forceRefresh: boolean = false) {
340
- if (!this.vaultIndex || forceRefresh)
341
- await buildLegacyVaultIndex(this)
303
+ if (!this.vaultIndex || forceRefresh) await buildLegacyVaultIndex(this)
342
304
  }
343
305
 
344
306
  /**
@@ -373,8 +335,7 @@ export class OroClient {
373
335
  return {
374
336
  ...consult,
375
337
  grant: {
376
- lockboxOwnerUuid:
377
- grant.lockboxOwnerUuid,
338
+ lockboxOwnerUuid: grant.lockboxOwnerUuid,
378
339
  lockboxUuid: grant.lockboxUuid,
379
340
  },
380
341
  }
@@ -405,9 +366,7 @@ export class OroClient {
405
366
 
406
367
  let rsaPub: Uint8Array
407
368
  if (indexOwnerUuid) {
408
- let base64IndexOwnerPubKey = (
409
- await this.guardClient.identityGet(indexOwnerUuid)
410
- ).publicKey
369
+ let base64IndexOwnerPubKey = (await this.guardClient.identityGet(indexOwnerUuid)).publicKey
411
370
  rsaPub = this.toolbox.decodeFromBase64(base64IndexOwnerPubKey)
412
371
  } else {
413
372
  rsaPub = this.rsa.public()
@@ -419,9 +378,7 @@ export class OroClient {
419
378
  let key = keyString as keyof VaultIndex
420
379
  switch (key) {
421
380
  case IndexKey.ConsultationLockbox:
422
- encryptedIndex[key] = (entries[
423
- key
424
- ] as IndexConsultLockbox[])
381
+ encryptedIndex[key] = (entries[key] as IndexConsultLockbox[])
425
382
  .map((e) => ({
426
383
  ...e,
427
384
  uniqueHash: e.consultationId,
@@ -444,9 +401,7 @@ export class OroClient {
444
401
  break
445
402
  //// DEPRECATED : REMOVE ME : BEGIN ///////////////////////////////////////////
446
403
  case IndexKey.Consultation:
447
- encryptedIndex[key] = (entries[
448
- key
449
- ] as IndexConsultLockbox[])
404
+ encryptedIndex[key] = (entries[key] as IndexConsultLockbox[])
450
405
  .map((e) => ({
451
406
  ...e,
452
407
  uniqueHash: this.toolbox.hashStringToBase64(
@@ -459,9 +414,7 @@ export class OroClient {
459
414
  .filter(
460
415
  (e) =>
461
416
  !this.vaultIndex ||
462
- !this.vaultIndex[IndexKey.Consultation]?.find(
463
- (v) => v.uniqueHash === e.uniqueHash
464
- )
417
+ !this.vaultIndex[IndexKey.Consultation]?.find((v) => v.uniqueHash === e.uniqueHash)
465
418
  )
466
419
  .map(
467
420
  (e: IndexConsultLockbox) =>
@@ -506,10 +459,7 @@ export class OroClient {
506
459
 
507
460
  // the data of the snapshot should not contain the `IndexEntry` data
508
461
  // (will create conflicts while updating)
509
- let encryptedIndexEntry = CryptoRSA.jsonWithPubEncryptToBase64(
510
- cleanedIndex,
511
- rsaPub
512
- )
462
+ let encryptedIndexEntry = CryptoRSA.jsonWithPubEncryptToBase64(cleanedIndex, rsaPub)
513
463
 
514
464
  // The encryptedIndexEntry can have the uuid and timstamp (for updating)
515
465
  let encryptedIndex: EncryptedIndexEntry = {
@@ -527,36 +477,19 @@ export class OroClient {
527
477
  * @param lockboxUuid
528
478
  * @param lockboxOwnerUuid the lockbox owner (ignored if lockbox is owned by self)
529
479
  */
530
- public async grantLockbox(
531
- granteeUuid: Uuid,
532
- lockboxUuid: Uuid,
533
- lockboxOwnerUuid?: Uuid
534
- ) {
480
+ public async grantLockbox(granteeUuid: Uuid, lockboxUuid: Uuid, lockboxOwnerUuid?: Uuid) {
535
481
  if (!this.rsa) throw IncompleteAuthentication
536
482
 
537
- let secret = (
538
- await this.getCachedSecretCryptor(lockboxUuid, lockboxOwnerUuid)
539
- ).key()
540
- let base64GranteePublicKey = (
541
- await this.guardClient.identityGet(granteeUuid)
542
- ).publicKey
543
- let granteePublicKey = this.toolbox.decodeFromBase64(
544
- base64GranteePublicKey
545
- )
483
+ let secret = (await this.getCachedSecretCryptor(lockboxUuid, lockboxOwnerUuid)).key()
484
+ let base64GranteePublicKey = (await this.guardClient.identityGet(granteeUuid)).publicKey
485
+ let granteePublicKey = this.toolbox.decodeFromBase64(base64GranteePublicKey)
546
486
 
547
- let granteeEncryptedSecret = CryptoRSA.bytesWithPubEncryptToBase64(
548
- secret,
549
- granteePublicKey
550
- )
487
+ let granteeEncryptedSecret = CryptoRSA.bytesWithPubEncryptToBase64(secret, granteePublicKey)
551
488
  let request: LockboxGrantRequest = {
552
489
  encryptedSecret: granteeEncryptedSecret,
553
490
  granteeUuid: granteeUuid,
554
491
  }
555
- await this.vaultClient.lockboxGrant(
556
- lockboxUuid,
557
- request,
558
- lockboxOwnerUuid
559
- )
492
+ await this.vaultClient.lockboxGrant(lockboxUuid, request, lockboxOwnerUuid)
560
493
  }
561
494
 
562
495
  /**
@@ -578,17 +511,12 @@ export class OroClient {
578
511
  ): Promise<DataCreateResponse> {
579
512
  if (!this.rsa) throw IncompleteAuthentication
580
513
 
581
- let symmetricEncryptor = await this.getCachedSecretCryptor(
582
- lockboxUuid,
583
- lockboxOwnerUuid
584
- )
514
+ let symmetricEncryptor = await this.getCachedSecretCryptor(lockboxUuid, lockboxOwnerUuid)
585
515
 
586
- let encryptedData = symmetricEncryptor.jsonEncryptToBase64Payload(
587
- message
588
- )
589
- let encryptedPrivateMeta = symmetricEncryptor.jsonEncryptToBase64Payload(
590
- { author: (await this.guardClient.whoAmI()).sub }
591
- )
516
+ let encryptedData = symmetricEncryptor.jsonEncryptToBase64Payload(message)
517
+ let encryptedPrivateMeta = symmetricEncryptor.jsonEncryptToBase64Payload({
518
+ author: (await this.guardClient.whoAmI()).sub,
519
+ })
592
520
 
593
521
  let meta = {
594
522
  consultationId,
@@ -603,12 +531,7 @@ export class OroClient {
603
531
  privateMetadata: encryptedPrivateMeta,
604
532
  }
605
533
 
606
- return this.tellerClient.lockboxDataStore(
607
- lockboxUuid,
608
- request,
609
- lockboxOwnerUuid,
610
- previousDataUuid
611
- )
534
+ return this.tellerClient.lockboxDataStore(lockboxUuid, request, lockboxOwnerUuid, previousDataUuid)
612
535
  }
613
536
 
614
537
  /**
@@ -630,21 +553,14 @@ export class OroClient {
630
553
  ): Promise<DataCreateResponse> {
631
554
  if (!this.rsa) throw IncompleteAuthentication
632
555
 
633
- let symmetricEncryptor = await this.getCachedSecretCryptor(
634
- lockboxUuid,
635
- lockboxOwnerUuid
636
- )
637
- let encryptedData = symmetricEncryptor.bytesEncryptToBase64Payload(
638
- new Uint8Array(await data.arrayBuffer())
639
- )
640
- let encryptedPrivateMeta = symmetricEncryptor.jsonEncryptToBase64Payload(
641
- {
642
- author: (await this.guardClient.whoAmI()).sub,
643
- fileName: data.name,
644
- lastModified: data.lastModified,
645
- size: data.size,
646
- }
647
- )
556
+ let symmetricEncryptor = await this.getCachedSecretCryptor(lockboxUuid, lockboxOwnerUuid)
557
+ let encryptedData = symmetricEncryptor.bytesEncryptToBase64Payload(new Uint8Array(await data.arrayBuffer()))
558
+ let encryptedPrivateMeta = symmetricEncryptor.jsonEncryptToBase64Payload({
559
+ author: (await this.guardClient.whoAmI()).sub,
560
+ fileName: data.name,
561
+ lastModified: data.lastModified,
562
+ size: data.size,
563
+ })
648
564
 
649
565
  let meta = {
650
566
  consultationId,
@@ -659,12 +575,7 @@ export class OroClient {
659
575
  privateMetadata: encryptedPrivateMeta,
660
576
  }
661
577
 
662
- return this.tellerClient.lockboxDataStore(
663
- lockboxUuid,
664
- request,
665
- lockboxOwnerUuid,
666
- previousDataUuid
667
- )
578
+ return this.tellerClient.lockboxDataStore(lockboxUuid, request, lockboxOwnerUuid, previousDataUuid)
668
579
  }
669
580
 
670
581
  /**
@@ -727,14 +638,9 @@ export class OroClient {
727
638
  ): Promise<DataCreateResponse> {
728
639
  if (!this.rsa) throw IncompleteAuthentication
729
640
 
730
- let symmetricEncryptor = await this.getCachedSecretCryptor(
731
- lockboxUuid,
732
- lockboxOwnerUuid
733
- )
641
+ let symmetricEncryptor = await this.getCachedSecretCryptor(lockboxUuid, lockboxOwnerUuid)
734
642
  let encryptedData = symmetricEncryptor.jsonEncryptToBase64Payload(data)
735
- let encryptedPrivateMeta = symmetricEncryptor.jsonEncryptToBase64Payload(
736
- privateMeta
737
- )
643
+ let encryptedPrivateMeta = symmetricEncryptor.jsonEncryptToBase64Payload(privateMeta)
738
644
 
739
645
  let request: LockboxDataRequest = {
740
646
  data: encryptedData,
@@ -742,12 +648,7 @@ export class OroClient {
742
648
  privateMetadata: encryptedPrivateMeta,
743
649
  }
744
650
 
745
- return this.tellerClient.lockboxDataStore(
746
- lockboxUuid,
747
- request,
748
- lockboxOwnerUuid,
749
- previousDataUuid
750
- )
651
+ return this.tellerClient.lockboxDataStore(lockboxUuid, request, lockboxOwnerUuid, previousDataUuid)
751
652
  }
752
653
 
753
654
  /**
@@ -766,14 +667,9 @@ export class OroClient {
766
667
  privateMetadata: Metadata,
767
668
  forceReplace: boolean = false
768
669
  ): Promise<Uuid> {
769
- let manifest = await this.vaultClient.lockboxManifestGet(
770
- lockboxUuid,
771
- publicMetadata
772
- )
670
+ let manifest = await this.vaultClient.lockboxManifestGet(lockboxUuid, publicMetadata)
773
671
  if (!forceReplace && manifest.length > 0) {
774
- console.log(
775
- `The data for ${JSON.stringify(publicMetadata)} already exist`
776
- )
672
+ console.log(`The data for ${JSON.stringify(publicMetadata)} already exist`)
777
673
  return manifest[0].dataUuid
778
674
  } else
779
675
  return (
@@ -783,16 +679,9 @@ export class OroClient {
783
679
  publicMetadata,
784
680
  privateMetadata,
785
681
  undefined,
786
- forceReplace && manifest.length > 0
787
- ? manifest[0].dataUuid
788
- : undefined // if forceReplace and data already exist, then replace data. Otherwise insert it
682
+ forceReplace && manifest.length > 0 ? manifest[0].dataUuid : undefined // if forceReplace and data already exist, then replace data. Otherwise insert it
789
683
  ).catch((err) => {
790
- console.error(
791
- `Error while upserting data ${JSON.stringify(
792
- publicMetadata
793
- )} data`,
794
- err
795
- )
684
+ console.error(`Error while upserting data ${JSON.stringify(publicMetadata)} data`, err)
796
685
  throw err
797
686
  })
798
687
  ).dataUuid
@@ -818,14 +707,9 @@ export class OroClient {
818
707
  previousDataUuid?: Uuid
819
708
  ): Promise<DataCreateResponse> {
820
709
  if (!this.rsa) throw IncompleteAuthentication
821
- let symmetricEncryptor = await this.getCachedSecretCryptor(
822
- lockboxUuid,
823
- lockboxOwnerUuid
824
- )
710
+ let symmetricEncryptor = await this.getCachedSecretCryptor(lockboxUuid, lockboxOwnerUuid)
825
711
  let encryptedData = symmetricEncryptor.bytesEncryptToBase64Payload(data)
826
- let encryptedPrivateMeta = symmetricEncryptor.jsonEncryptToBase64Payload(
827
- privateMeta
828
- )
712
+ let encryptedPrivateMeta = symmetricEncryptor.jsonEncryptToBase64Payload(privateMeta)
829
713
 
830
714
  let request: LockboxDataRequest = {
831
715
  data: encryptedData,
@@ -833,12 +717,7 @@ export class OroClient {
833
717
  privateMetadata: encryptedPrivateMeta,
834
718
  }
835
719
 
836
- return this.tellerClient.lockboxDataStore(
837
- lockboxUuid,
838
- request,
839
- lockboxOwnerUuid,
840
- previousDataUuid
841
- )
720
+ return this.tellerClient.lockboxDataStore(lockboxUuid, request, lockboxOwnerUuid, previousDataUuid)
842
721
  }
843
722
 
844
723
  /**
@@ -852,25 +731,15 @@ export class OroClient {
852
731
  * @param lockboxOwnerUuid the lockbox owner (ignored if lockbox is owned by self)
853
732
  * @returns the data specified by the generic type <T>
854
733
  */
855
- public async getJsonData<T = any>(
856
- lockboxUuid: Uuid,
857
- dataUuid: Uuid,
858
- lockboxOwnerUuid?: Uuid
859
- ): Promise<T> {
734
+ public async getJsonData<T = any>(lockboxUuid: Uuid, dataUuid: Uuid, lockboxOwnerUuid?: Uuid): Promise<T> {
860
735
  if (!this.rsa) throw IncompleteAuthentication
861
736
 
862
737
  let [encryptedPayload, symmetricDecryptor] = await Promise.all([
863
- this.vaultClient.lockboxDataGet(
864
- lockboxUuid,
865
- dataUuid,
866
- lockboxOwnerUuid
867
- ),
738
+ this.vaultClient.lockboxDataGet(lockboxUuid, dataUuid, lockboxOwnerUuid),
868
739
  this.getCachedSecretCryptor(lockboxUuid, lockboxOwnerUuid),
869
740
  ])
870
741
 
871
- return symmetricDecryptor.base64PayloadDecryptToJson(
872
- encryptedPayload.data
873
- )
742
+ return symmetricDecryptor.base64PayloadDecryptToJson(encryptedPayload.data)
874
743
  }
875
744
  /**
876
745
  * @description Fetches and decrypts the lockbox data with the cached shared secret.
@@ -879,25 +748,15 @@ export class OroClient {
879
748
  * @param lockboxOwnerUuid the lockbox owner (ignored if lockbox is owned by self)
880
749
  * @returns the bytes data
881
750
  */
882
- public async getBytesData(
883
- lockboxUuid: Uuid,
884
- dataUuid: Uuid,
885
- lockboxOwnerUuid?: Uuid
886
- ): Promise<Uint8Array> {
751
+ public async getBytesData(lockboxUuid: Uuid, dataUuid: Uuid, lockboxOwnerUuid?: Uuid): Promise<Uint8Array> {
887
752
  if (!this.rsa) throw IncompleteAuthentication
888
753
 
889
754
  let [encryptedPayload, symmetricDecryptor] = await Promise.all([
890
- this.vaultClient.lockboxDataGet(
891
- lockboxUuid,
892
- dataUuid,
893
- lockboxOwnerUuid
894
- ),
755
+ this.vaultClient.lockboxDataGet(lockboxUuid, dataUuid, lockboxOwnerUuid),
895
756
  this.getCachedSecretCryptor(lockboxUuid, lockboxOwnerUuid),
896
757
  ])
897
758
 
898
- return symmetricDecryptor.base64PayloadDecryptToBytes(
899
- encryptedPayload.data
900
- )
759
+ return symmetricDecryptor.base64PayloadDecryptToBytes(encryptedPayload.data)
901
760
  }
902
761
 
903
762
  /**
@@ -910,21 +769,19 @@ export class OroClient {
910
769
  * @param filter: the consultationId in which the grant exists
911
770
  * @returns decrypted lockboxes granted to user
912
771
  */
913
- public async getGrants(
914
- filter?: { consultationId: Uuid },
915
- forceRefresh: boolean = false
916
- ): Promise<Grant[]> {
772
+ public async getGrants(filter?: { consultationId: Uuid }, forceRefresh: boolean = false): Promise<Grant[]> {
917
773
  if (!this.rsa) throw IncompleteAuthentication
918
774
 
919
775
  let filterString = JSON.stringify(filter)
920
776
  // retrieves cached grants
921
777
  // Note: if filters is set to empty, it will be stored in the `undefined` key
922
- if (!forceRefresh && this.cachedMetadataGrants[filterString])
923
- return this.cachedMetadataGrants[filterString]
778
+ if (!forceRefresh && this.cachedMetadataGrants[filterString]) return this.cachedMetadataGrants[filterString]
924
779
 
925
780
  // retrieves the consult lockbox from the vault directly if it exists
926
781
  // Note: will work only if the filter being applied is exclusively a consult id
927
- const grantsByConsultLockbox = (await this.vaultClient.vaultIndexGet([IndexKey.ConsultationLockbox], [filter?.consultationId!]))[IndexKey.ConsultationLockbox]
782
+ const grantsByConsultLockbox = (
783
+ await this.vaultClient.vaultIndexGet([IndexKey.ConsultationLockbox], [filter?.consultationId!])
784
+ )[IndexKey.ConsultationLockbox]
928
785
  const decryptedConsults = decryptConsultLockboxGrants(grantsByConsultLockbox ?? [], this.rsa)
929
786
  if (decryptedConsults.length > 0) {
930
787
  console.info('[sdk:index] Grants found in user`s constant time secure index')
@@ -935,12 +792,7 @@ export class OroClient {
935
792
  let encryptedGrants
936
793
  // if there are no grants with the applied filter from index, attempt for naive filter with backwards compatibility
937
794
  if (filter) {
938
- encryptedGrants = await filterGrantsWithLockboxMetadata(
939
- this,
940
- filter,
941
- this.vaultIndex,
942
- forceRefresh
943
- )
795
+ encryptedGrants = await filterGrantsWithLockboxMetadata(this, filter, this.vaultIndex, forceRefresh)
944
796
  } else {
945
797
  encryptedGrants = (await this.vaultClient.grantsGet()).grants
946
798
  }
@@ -958,22 +810,12 @@ export class OroClient {
958
810
  * @param lockboxOwnerUuid the lockbox owner (ignored if lockbox is owned by self)
959
811
  * @returns
960
812
  */
961
- async getCachedSecretCryptor(
962
- lockboxUuid: string,
963
- lockboxOwnerUuid?: string
964
- ): Promise<OroToolbox.CryptoChaCha> {
813
+ async getCachedSecretCryptor(lockboxUuid: string, lockboxOwnerUuid?: string): Promise<OroToolbox.CryptoChaCha> {
965
814
  if (!this.rsa) throw IncompleteAuthentication
966
815
 
967
- let index = this.secrets.findIndex(
968
- (secret) => secret.lockboxUuid === lockboxUuid
969
- )
816
+ let index = this.secrets.findIndex((secret) => secret.lockboxUuid === lockboxUuid)
970
817
  if (index === -1) {
971
- let encryptedSecret = (
972
- await this.vaultClient.lockboxSecretGet(
973
- lockboxUuid,
974
- lockboxOwnerUuid
975
- )
976
- ).sharedSecret
818
+ let encryptedSecret = (await this.vaultClient.lockboxSecretGet(lockboxUuid, lockboxOwnerUuid)).sharedSecret
977
819
 
978
820
  let secret = this.rsa.base64DecryptToBytes(encryptedSecret)
979
821
  let cryptor = this.toolbox.CryptoChaCha.fromKey(secret)
@@ -995,17 +837,10 @@ export class OroClient {
995
837
  */
996
838
  public async getPersonalInformationsFromConsultId(
997
839
  consultationId: Uuid,
998
- category:
999
- | MetadataCategory.Personal
1000
- | MetadataCategory.ChildPersonal
1001
- | MetadataCategory.OtherPersonal,
840
+ category: MetadataCategory.Personal | MetadataCategory.ChildPersonal | MetadataCategory.OtherPersonal,
1002
841
  forceRefresh = false
1003
842
  ): Promise<LocalizedData<PopulatedWorkflowData>[]> {
1004
- return this.getMetaCategoryFromConsultId(
1005
- consultationId,
1006
- category,
1007
- forceRefresh
1008
- )
843
+ return this.getMetaCategoryFromConsultId(consultationId, category, forceRefresh)
1009
844
  }
1010
845
 
1011
846
  /**
@@ -1020,11 +855,7 @@ export class OroClient {
1020
855
  consultationId: Uuid,
1021
856
  forceRefresh = false
1022
857
  ): Promise<LocalizedData<PopulatedWorkflowData>[]> {
1023
- return this.getMetaCategoryFromConsultId(
1024
- consultationId,
1025
- MetadataCategory.Medical,
1026
- forceRefresh
1027
- )
858
+ return this.getMetaCategoryFromConsultId(consultationId, MetadataCategory.Medical, forceRefresh)
1028
859
  }
1029
860
 
1030
861
  private async getMetaCategoryFromConsultId(
@@ -1069,10 +900,7 @@ export class OroClient {
1069
900
  lockboxOwnerUuid: grant.lockboxOwnerUuid,
1070
901
  lockboxUuid: grant.lockboxUuid!,
1071
902
  dataUuid: entry.dataUuid,
1072
- data: await this.getJsonData<PopulatedWorkflowData>(
1073
- grant.lockboxUuid!,
1074
- entry.dataUuid
1075
- ),
903
+ data: await this.getJsonData<PopulatedWorkflowData>(grant.lockboxUuid!, entry.dataUuid),
1076
904
  }
1077
905
  })
1078
906
  )
@@ -1086,12 +914,8 @@ export class OroClient {
1086
914
  * @param userId The user Id
1087
915
  * @returns the personal data
1088
916
  */
1089
- public async getPersonalInformations(
1090
- userId: Uuid
1091
- ): Promise<LocalizedData<PopulatedWorkflowData>> {
1092
- const grant = (await this.getGrants()).find(
1093
- (lockbox) => lockbox.lockboxOwnerUuid === userId
1094
- )
917
+ public async getPersonalInformations(userId: Uuid): Promise<LocalizedData<PopulatedWorkflowData>> {
918
+ const grant = (await this.getGrants()).find((lockbox) => lockbox.lockboxOwnerUuid === userId)
1095
919
 
1096
920
  if (!grant) {
1097
921
  throw MissingGrant
@@ -1119,10 +943,7 @@ export class OroClient {
1119
943
  lockboxOwnerUuid,
1120
944
  lockboxUuid,
1121
945
  dataUuid: identificationDataUuid,
1122
- data: await this.getJsonData<PopulatedWorkflowData>(
1123
- lockboxUuid,
1124
- identificationDataUuid
1125
- ),
946
+ data: await this.getJsonData<PopulatedWorkflowData>(lockboxUuid, identificationDataUuid),
1126
947
  }
1127
948
  }
1128
949
 
@@ -1132,9 +953,7 @@ export class OroClient {
1132
953
  * @param consultationId The consultationId
1133
954
  * @returns the grant
1134
955
  */
1135
- public async getGrantFromConsultId(
1136
- consultationId: Uuid
1137
- ): Promise<Grant | undefined> {
956
+ public async getGrantFromConsultId(consultationId: Uuid): Promise<Grant | undefined> {
1138
957
  let grants = await this.getGrants({ consultationId })
1139
958
 
1140
959
  if (grants.length === 0) {
@@ -1149,9 +968,7 @@ export class OroClient {
1149
968
  * @param consultationId The consultation Id
1150
969
  * @returns the identity
1151
970
  */
1152
- public async getIdentityFromConsultId(
1153
- consultationId: Uuid
1154
- ): Promise<IdentityResponse | undefined> {
971
+ public async getIdentityFromConsultId(consultationId: Uuid): Promise<IdentityResponse | undefined> {
1155
972
  const grant = await this.getGrantFromConsultId(consultationId)
1156
973
 
1157
974
  if (grant && grant.lockboxOwnerUuid) {
@@ -1184,34 +1001,26 @@ export class OroClient {
1184
1001
  expandPrivateMetadata,
1185
1002
  lockboxOwnerUuid,
1186
1003
  })
1187
- if (!forceRefresh && this.cachedManifest[manifestKey])
1188
- return this.cachedManifest[manifestKey]
1189
-
1190
- return this.vaultClient
1191
- .lockboxManifestGet(lockboxUuid, filter, lockboxOwnerUuid)
1192
- .then((manifest) => {
1193
- return Promise.all(
1194
- manifest.map(async (entry) => {
1195
- if (
1196
- expandPrivateMetadata &&
1197
- entry.metadata.privateMetadata
1198
- ) {
1199
- let privateMeta = await this.getJsonData<Metadata>(
1200
- lockboxUuid!,
1201
- entry.metadata.privateMetadata,
1202
- lockboxOwnerUuid
1203
- )
1204
- entry.metadata = {
1205
- ...entry.metadata,
1206
- ...privateMeta,
1207
- }
1004
+ if (!forceRefresh && this.cachedManifest[manifestKey]) return this.cachedManifest[manifestKey]
1005
+
1006
+ return this.vaultClient.lockboxManifestGet(lockboxUuid, filter, lockboxOwnerUuid).then((manifest) => {
1007
+ return Promise.all(
1008
+ manifest.map(async (entry) => {
1009
+ if (expandPrivateMetadata && entry.metadata.privateMetadata) {
1010
+ let privateMeta = await this.getJsonData<Metadata>(
1011
+ lockboxUuid!,
1012
+ entry.metadata.privateMetadata,
1013
+ lockboxOwnerUuid
1014
+ )
1015
+ entry.metadata = {
1016
+ ...entry.metadata,
1017
+ ...privateMeta,
1208
1018
  }
1209
- return entry
1210
- })
1211
- ).then(
1212
- (manifest) => (this.cachedManifest[manifestKey] = manifest)
1213
- )
1214
- })
1019
+ }
1020
+ return entry
1021
+ })
1022
+ ).then((manifest) => (this.cachedManifest[manifestKey] = manifest))
1023
+ })
1215
1024
  }
1216
1025
 
1217
1026
  /**
@@ -1285,10 +1094,7 @@ export class OroClient {
1285
1094
  * @param grant The grant
1286
1095
  * @returns the user preference
1287
1096
  */
1288
- public async getDataFromGrant<T = any>(
1289
- grant: Grant,
1290
- filter: Metadata
1291
- ): Promise<LocalizedData<T>> {
1097
+ public async getDataFromGrant<T = any>(grant: Grant, filter: Metadata): Promise<LocalizedData<T>> {
1292
1098
  const { lockboxUuid, lockboxOwnerUuid } = grant
1293
1099
 
1294
1100
  if (!lockboxUuid) throw MissingLockbox
@@ -1308,10 +1114,7 @@ export class OroClient {
1308
1114
  lockboxOwnerUuid,
1309
1115
  lockboxUuid,
1310
1116
  dataUuid: identificationDataUuid,
1311
- data: await this.getJsonData<T>(
1312
- lockboxUuid,
1313
- identificationDataUuid
1314
- ),
1117
+ data: await this.getJsonData<T>(lockboxUuid, identificationDataUuid),
1315
1118
  }
1316
1119
  }
1317
1120
 
@@ -1320,9 +1123,7 @@ export class OroClient {
1320
1123
  * @param consultationId The related consultationId
1321
1124
  * @returns the user preference
1322
1125
  */
1323
- public async getUserPreferenceFromConsultId(
1324
- consultationId: string
1325
- ): Promise<LocalizedData<UserPreference>> {
1126
+ public async getUserPreferenceFromConsultId(consultationId: string): Promise<LocalizedData<UserPreference>> {
1326
1127
  const grant = await this.getGrantFromConsultId(consultationId)
1327
1128
 
1328
1129
  if (!grant) throw MissingGrant
@@ -1338,12 +1139,8 @@ export class OroClient {
1338
1139
  * @param identity The identity to use
1339
1140
  * @returns the user preference
1340
1141
  */
1341
- public async getUserPreference(
1342
- identity: IdentityResponse
1343
- ): Promise<LocalizedData<UserPreference>> {
1344
- const grant = (await this.getGrants()).find(
1345
- (lockbox) => lockbox.lockboxOwnerUuid === identity.id
1346
- )
1142
+ public async getUserPreference(identity: IdentityResponse): Promise<LocalizedData<UserPreference>> {
1143
+ const grant = (await this.getGrants()).find((lockbox) => lockbox.lockboxOwnerUuid === identity.id)
1347
1144
 
1348
1145
  if (!grant) throw MissingGrant
1349
1146
 
@@ -1358,9 +1155,7 @@ export class OroClient {
1358
1155
  * @param consultationId The related consultationId
1359
1156
  * @returns the user preference
1360
1157
  */
1361
- public async getRecoveryDataFromConsultId(
1362
- consultationId: string
1363
- ): Promise<LocalizedData<RecoveryData>> {
1158
+ public async getRecoveryDataFromConsultId(consultationId: string): Promise<LocalizedData<RecoveryData>> {
1364
1159
  const grant = await this.getGrantFromConsultId(consultationId)
1365
1160
 
1366
1161
  if (!grant) throw MissingGrant
@@ -1376,12 +1171,8 @@ export class OroClient {
1376
1171
  * @param identity The identity to use
1377
1172
  * @returns the user preference
1378
1173
  */
1379
- public async getRecoveryData(
1380
- identity: IdentityResponse
1381
- ): Promise<LocalizedData<RecoveryData>> {
1382
- const grant = (await this.getGrants()).find(
1383
- (lockbox) => lockbox.lockboxOwnerUuid === identity.id
1384
- )
1174
+ public async getRecoveryData(identity: IdentityResponse): Promise<LocalizedData<RecoveryData>> {
1175
+ const grant = (await this.getGrants()).find((lockbox) => lockbox.lockboxOwnerUuid === identity.id)
1385
1176
 
1386
1177
  if (!grant) throw MissingGrant
1387
1178
 
@@ -1401,10 +1192,7 @@ export class OroClient {
1401
1192
  * @param practiceUuid the uuid of the practice to look consult into
1402
1193
  * @returns the list of consults
1403
1194
  */
1404
- public async getAssignedConsultations(
1405
- practiceUuid: Uuid,
1406
- forceRefresh: boolean = false
1407
- ): Promise<Consult[]> {
1195
+ public async getAssignedConsultations(practiceUuid: Uuid, forceRefresh: boolean = false): Promise<Consult[]> {
1408
1196
  return Promise.all(
1409
1197
  (await this.getGrants(undefined, forceRefresh)).map((grant) =>
1410
1198
  this.getLockboxManifest(
@@ -1420,10 +1208,7 @@ export class OroClient {
1420
1208
  Promise.all(
1421
1209
  manifest.map(
1422
1210
  async (entry) =>
1423
- await this.consultClient.getConsultByUUID(
1424
- entry.metadata.consultationId,
1425
- practiceUuid
1426
- )
1211
+ await this.consultClient.getConsultByUUID(entry.metadata.consultationId, practiceUuid)
1427
1212
  )
1428
1213
  ).then((promise) => promise.flat())
1429
1214
  )
@@ -1456,19 +1241,13 @@ export class OroClient {
1456
1241
  )
1457
1242
  )
1458
1243
  .flat()
1459
- .map(
1460
- (metadata: { consultationId: string }) =>
1461
- metadata.consultationId
1462
- )
1244
+ .map((metadata: { consultationId: string }) => metadata.consultationId)
1463
1245
 
1464
1246
  if (consultationsInLockbox.length == 0) return []
1465
1247
 
1466
1248
  return await Promise.all(
1467
1249
  consultationsInLockbox.map(async (consultId: string) => {
1468
- return await this.consultClient.getConsultByUUID(
1469
- consultId,
1470
- practiceUuid
1471
- )
1250
+ return await this.consultClient.getConsultByUUID(consultId, practiceUuid)
1472
1251
  })
1473
1252
  )
1474
1253
  }
@@ -1518,9 +1297,7 @@ export class OroClient {
1518
1297
  * @param consultationId
1519
1298
  * @returns
1520
1299
  */
1521
- public async getPatientPrescriptionsList(
1522
- consultationId: Uuid
1523
- ): Promise<Document[]> {
1300
+ public async getPatientPrescriptionsList(consultationId: Uuid): Promise<Document[]> {
1524
1301
  return this.getPatientDocumentsList(
1525
1302
  {
1526
1303
  category: MetadataCategory.Consultation,
@@ -1536,9 +1313,7 @@ export class OroClient {
1536
1313
  * @param consultationId
1537
1314
  * @returns
1538
1315
  */
1539
- public async getPatientResultsList(
1540
- consultationId: Uuid
1541
- ): Promise<Document[]> {
1316
+ public async getPatientResultsList(consultationId: Uuid): Promise<Document[]> {
1542
1317
  return this.getPatientDocumentsList(
1543
1318
  {
1544
1319
  category: MetadataCategory.Consultation,
@@ -1554,9 +1329,7 @@ export class OroClient {
1554
1329
  * @param consultationId
1555
1330
  * @returns Document[] corresponding to the patient treatment plan options
1556
1331
  */
1557
- public async getPatientTreatmentPlans(
1558
- consultationId: Uuid
1559
- ): Promise<Document[]> {
1332
+ public async getPatientTreatmentPlans(consultationId: Uuid): Promise<Document[]> {
1560
1333
  return this.getPatientDocumentsList(
1561
1334
  {
1562
1335
  category: MetadataCategory.Consultation,
@@ -1573,10 +1346,7 @@ export class OroClient {
1573
1346
  * @param treatmentPlanId
1574
1347
  * @returns
1575
1348
  */
1576
- public async getPatientTreatmentPlanByUuid(
1577
- consultationId: Uuid,
1578
- treatmentPlanId: Uuid
1579
- ): Promise<Document[]> {
1349
+ public async getPatientTreatmentPlanByUuid(consultationId: Uuid, treatmentPlanId: Uuid): Promise<Document[]> {
1580
1350
  return this.getPatientDocumentsList(
1581
1351
  {
1582
1352
  category: MetadataCategory.Consultation,
@@ -1613,16 +1383,13 @@ export class OroClient {
1613
1383
  true
1614
1384
  ).then((manifest) =>
1615
1385
  Promise.all(
1616
- manifest.map(
1617
- async (entry): Promise<Document> => {
1618
- return {
1619
- lockboxOwnerUuid:
1620
- grant.lockboxOwnerUuid,
1621
- lockboxUuid: grant.lockboxUuid!,
1622
- ...entry,
1623
- }
1386
+ manifest.map(async (entry): Promise<Document> => {
1387
+ return {
1388
+ lockboxOwnerUuid: grant.lockboxOwnerUuid,
1389
+ lockboxUuid: grant.lockboxUuid!,
1390
+ ...entry,
1624
1391
  }
1625
- )
1392
+ })
1626
1393
  )
1627
1394
  )
1628
1395
  )
@@ -1648,34 +1415,23 @@ export class OroClient {
1648
1415
  recoverySecurityAnswers: string[],
1649
1416
  threshold: number
1650
1417
  ) {
1651
- let shards: SecretShard[] = (await this.guardClient.identityGet(id))
1652
- .recoverySecurityQuestions
1418
+ let shards: SecretShard[] = (await this.guardClient.identityGet(id)).recoverySecurityQuestions
1653
1419
  let answeredShards = shards
1654
1420
  .filter((shard: any) => {
1655
1421
  // filters all answered security questions
1656
- let indexOfQuestion = recoverySecurityQuestions.indexOf(
1657
- shard.securityQuestion
1658
- )
1422
+ let indexOfQuestion = recoverySecurityQuestions.indexOf(shard.securityQuestion)
1659
1423
  if (indexOfQuestion === -1) return false
1660
- return (
1661
- recoverySecurityAnswers[indexOfQuestion] &&
1662
- recoverySecurityAnswers[indexOfQuestion] != ''
1663
- )
1424
+ return recoverySecurityAnswers[indexOfQuestion] && recoverySecurityAnswers[indexOfQuestion] != ''
1664
1425
  })
1665
1426
  .map((item: any) => {
1666
1427
  // appends the security answer to the answered shards
1667
- let index = recoverySecurityQuestions.indexOf(
1668
- item.securityQuestion
1669
- )
1428
+ let index = recoverySecurityQuestions.indexOf(item.securityQuestion)
1670
1429
  item.securityAnswer = recoverySecurityAnswers[index]
1671
1430
  return item
1672
1431
  })
1673
1432
  try {
1674
1433
  // reconstructs the key from the answered security answers
1675
- let privateKey = this.toolbox.reconstructSecret(
1676
- answeredShards,
1677
- threshold
1678
- )
1434
+ let privateKey = this.toolbox.reconstructSecret(answeredShards, threshold)
1679
1435
  this.rsa = this.toolbox.CryptoRSA.fromKey(privateKey)
1680
1436
  } catch (e) {
1681
1437
  console.error(e)
@@ -1692,18 +1448,12 @@ export class OroClient {
1692
1448
  let identity = await this.guardClient.identityGet(id)
1693
1449
 
1694
1450
  let recoveryPayload = identity.recoveryPassword
1695
- let symmetricDecryptor = this.toolbox.CryptoChaCha.fromPassphrase(
1696
- password
1697
- )
1698
- let privateKey = symmetricDecryptor.base64PayloadDecryptToBytes(
1699
- recoveryPayload
1700
- )
1451
+ let symmetricDecryptor = this.toolbox.CryptoChaCha.fromPassphrase(password)
1452
+ let privateKey = symmetricDecryptor.base64PayloadDecryptToBytes(recoveryPayload)
1701
1453
 
1702
1454
  if (identity.recoveryLogin) {
1703
1455
  //Ensure we can recover from a page reload
1704
- let symetricEncryptor = this.toolbox.CryptoChaCha.fromPassphrase(
1705
- identity.recoveryLogin
1706
- )
1456
+ let symetricEncryptor = this.toolbox.CryptoChaCha.fromPassphrase(identity.recoveryLogin)
1707
1457
  sessionStorage.setItem(
1708
1458
  sessionStorePrivateKeyName(id),
1709
1459
  symetricEncryptor.bytesEncryptToBase64Payload(privateKey)
@@ -1720,14 +1470,9 @@ export class OroClient {
1720
1470
  * @param masterKey
1721
1471
  */
1722
1472
  public async recoverPrivateKeyFromMasterKey(id: Uuid, masterKey: string) {
1723
- let recoveryPayload = (await this.guardClient.identityGet(id))
1724
- .recoveryMasterKey
1725
- let symmetricDecryptor = this.toolbox.CryptoChaCha.fromPassphrase(
1726
- masterKey
1727
- )
1728
- let privateKey = symmetricDecryptor.base64PayloadDecryptToBytes(
1729
- recoveryPayload
1730
- )
1473
+ let recoveryPayload = (await this.guardClient.identityGet(id)).recoveryMasterKey
1474
+ let symmetricDecryptor = this.toolbox.CryptoChaCha.fromPassphrase(masterKey)
1475
+ let privateKey = symmetricDecryptor.base64PayloadDecryptToBytes(recoveryPayload)
1731
1476
  this.rsa = this.toolbox.CryptoRSA.fromKey(privateKey)
1732
1477
  }
1733
1478
 
@@ -1770,28 +1515,16 @@ export class OroClient {
1770
1515
  * @param newPassword
1771
1516
  * @param oldPassword
1772
1517
  */
1773
- public async updatePassword(
1774
- id: Uuid,
1775
- newPassword: string,
1776
- oldPassword?: string
1777
- ) {
1518
+ public async updatePassword(id: Uuid, newPassword: string, oldPassword?: string) {
1778
1519
  if (!this.rsa) throw IncompleteAuthentication
1779
1520
 
1780
- let symmetricEncryptor = this.toolbox.CryptoChaCha.fromPassphrase(
1781
- newPassword
1782
- )
1783
- let passwordPayload = symmetricEncryptor.bytesEncryptToBase64Payload(
1784
- this.rsa.private()
1785
- )
1521
+ let symmetricEncryptor = this.toolbox.CryptoChaCha.fromPassphrase(newPassword)
1522
+ let passwordPayload = symmetricEncryptor.bytesEncryptToBase64Payload(this.rsa.private())
1786
1523
  if (oldPassword) {
1787
- oldPassword = this.toolbox.hashStringToBase64(
1788
- this.toolbox.hashStringToBase64(oldPassword)
1789
- )
1524
+ oldPassword = this.toolbox.hashStringToBase64(this.toolbox.hashStringToBase64(oldPassword))
1790
1525
  }
1791
1526
 
1792
- newPassword = this.toolbox.hashStringToBase64(
1793
- this.toolbox.hashStringToBase64(newPassword)
1794
- )
1527
+ newPassword = this.toolbox.hashStringToBase64(this.toolbox.hashStringToBase64(newPassword))
1795
1528
 
1796
1529
  let updateRequest = {
1797
1530
  password: {
@@ -1815,17 +1548,10 @@ export class OroClient {
1815
1548
  async updateMasterKey(id: Uuid, masterKey: string, lockboxUuid: Uuid) {
1816
1549
  if (!this.rsa) throw IncompleteAuthentication
1817
1550
 
1818
- let symmetricEncryptor = this.toolbox.CryptoChaCha.fromPassphrase(
1819
- masterKey
1820
- )
1821
- let masterKeyPayload = symmetricEncryptor.bytesEncryptToBase64Payload(
1822
- this.rsa.private()
1823
- )
1551
+ let symmetricEncryptor = this.toolbox.CryptoChaCha.fromPassphrase(masterKey)
1552
+ let masterKeyPayload = symmetricEncryptor.bytesEncryptToBase64Payload(this.rsa.private())
1824
1553
  let updateRequest = { recoveryMasterKey: masterKeyPayload }
1825
- const updatedIdentity = await this.guardClient.identityUpdate(
1826
- id,
1827
- updateRequest
1828
- )
1554
+ const updatedIdentity = await this.guardClient.identityUpdate(id, updateRequest)
1829
1555
 
1830
1556
  await this.getOrInsertJsonData<RecoveryMeta>(
1831
1557
  lockboxUuid,