@raytio/core 9.0.3 → 10.1.0

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 (145) hide show
  1. package/CHANGELOG.md +161 -0
  2. package/README.md +77 -4
  3. package/dist/accessApplication/createAA.d.ts +17 -17
  4. package/dist/accessApplication/createAA.js +71 -71
  5. package/dist/accessApplication/index.d.ts +1 -1
  6. package/dist/accessApplication/index.js +17 -13
  7. package/dist/crypto/cognitoAttributes.d.ts +15 -15
  8. package/dist/crypto/cognitoAttributes.js +33 -33
  9. package/dist/crypto/decryptKeys.d.ts +1 -1
  10. package/dist/crypto/decryptKeys.js +33 -33
  11. package/dist/crypto/decryptSharedData.d.ts +26 -26
  12. package/dist/crypto/decryptSharedData.js +38 -38
  13. package/dist/crypto/getAADecryptor.d.ts +16 -11
  14. package/dist/crypto/getAADecryptor.js +20 -20
  15. package/dist/crypto/helpers.d.ts +18 -18
  16. package/dist/crypto/helpers.js +26 -26
  17. package/dist/crypto/index.d.ts +4 -4
  18. package/dist/crypto/index.js +21 -17
  19. package/dist/general/conditional.d.ts +17 -7
  20. package/dist/general/conditional.js +32 -22
  21. package/dist/general/date.d.ts +2 -0
  22. package/dist/general/date.js +18 -0
  23. package/dist/general/index.d.ts +4 -3
  24. package/dist/general/index.js +20 -15
  25. package/dist/general/password.d.ts +10 -8
  26. package/dist/general/password.js +31 -29
  27. package/dist/general/types.d.ts +6 -6
  28. package/dist/general/types.js +13 -13
  29. package/dist/index.d.ts +6 -6
  30. package/dist/index.js +22 -18
  31. package/dist/rules/calculateScore.d.ts +23 -11
  32. package/dist/rules/calculateScore.js +76 -52
  33. package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
  34. package/dist/rules/convertInstanceToRuleInput.js +139 -139
  35. package/dist/rules/evaluateScoreCondition.d.ts +2 -2
  36. package/dist/rules/evaluateScoreCondition.js +45 -45
  37. package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -8
  38. package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -11
  39. package/dist/rules/helpers/checkTypeofValue.d.ts +9 -3
  40. package/dist/rules/helpers/checkTypeofValue.js +55 -43
  41. package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
  42. package/dist/rules/helpers/getLhsTypeofValue.js +1 -0
  43. package/dist/rules/helpers/getValueFromPath.d.ts +2 -0
  44. package/dist/rules/helpers/getValueFromPath.js +35 -0
  45. package/dist/rules/helpers/getValuesFromPath.d.ts +3 -3
  46. package/dist/rules/helpers/getValuesFromPath.js +50 -50
  47. package/dist/rules/helpers/index.d.ts +5 -5
  48. package/dist/rules/helpers/index.js +21 -17
  49. package/dist/rules/helpers/rebuildInfiniteValues.d.ts +3 -0
  50. package/dist/rules/helpers/rebuildInfiniteValues.js +6 -0
  51. package/dist/rules/helpers/symbols.d.ts +2 -2
  52. package/dist/rules/helpers/symbols.js +5 -5
  53. package/dist/rules/helpers/thresholds.d.ts +5 -5
  54. package/dist/rules/helpers/thresholds.js +47 -47
  55. package/dist/rules/index.d.ts +7 -6
  56. package/dist/rules/index.js +25 -20
  57. package/dist/rules/isScoreResultValid.d.ts +2 -0
  58. package/dist/rules/isScoreResultValid.js +9 -0
  59. package/dist/rules/operators/array.d.ts +2 -0
  60. package/dist/rules/operators/array.js +74 -0
  61. package/dist/rules/operators/bool.d.ts +2 -2
  62. package/dist/rules/operators/bool.js +17 -17
  63. package/dist/rules/operators/date.d.ts +2 -2
  64. package/dist/rules/operators/date.js +91 -91
  65. package/dist/rules/operators/hfield.d.ts +2 -2
  66. package/dist/rules/operators/hfield.js +33 -33
  67. package/dist/rules/operators/hschema.d.ts +2 -2
  68. package/dist/rules/operators/hschema.js +21 -21
  69. package/dist/rules/operators/index.d.ts +3 -3
  70. package/dist/rules/operators/index.js +11 -11
  71. package/dist/rules/operators/number.d.ts +2 -2
  72. package/dist/rules/operators/number.js +41 -41
  73. package/dist/rules/operators/string.d.ts +2 -2
  74. package/dist/rules/operators/string.js +58 -58
  75. package/dist/rules/types/config.d.ts +91 -86
  76. package/dist/rules/types/config.js +2 -2
  77. package/dist/rules/types/dataValueTypes.d.ts +19 -19
  78. package/dist/rules/types/dataValueTypes.js +4 -4
  79. package/dist/rules/types/index.d.ts +3 -3
  80. package/dist/rules/types/index.js +19 -15
  81. package/dist/rules/types/internal.d.ts +20 -20
  82. package/dist/rules/types/internal.js +2 -2
  83. package/dist/rules/types/operators.d.ts +19 -0
  84. package/dist/rules/types/operators.js +2 -0
  85. package/dist/rules/types/score.d.ts +50 -0
  86. package/dist/rules/types/score.js +2 -0
  87. package/dist/rules/validate.d.ts +6 -0
  88. package/dist/rules/validate.js +14 -0
  89. package/dist/rules/version.d.ts +1 -0
  90. package/dist/rules/version.js +5 -0
  91. package/dist/schema/index.d.ts +1 -1
  92. package/dist/schema/index.js +17 -13
  93. package/dist/schema/labels.d.ts +2 -2
  94. package/dist/schema/labels.js +20 -20
  95. package/dist/util/canonicalJsonify.d.ts +1 -1
  96. package/dist/util/canonicalJsonify.js +50 -50
  97. package/dist/util/conditional.d.ts +7 -0
  98. package/dist/util/conditional.js +15 -0
  99. package/dist/util/handleResponse.d.ts +1 -1
  100. package/dist/util/handleResponse.js +21 -21
  101. package/dist/util/hash.d.ts +1 -0
  102. package/dist/util/hash.js +11 -0
  103. package/dist/util/index.d.ts +2 -2
  104. package/dist/util/index.js +18 -14
  105. package/dist/verifications/checkSingleVerification.d.ts +9 -0
  106. package/dist/verifications/checkSingleVerification.js +29 -0
  107. package/dist/verifications/checkVerifications.d.ts +1 -0
  108. package/dist/verifications/checkVerifications.js +16 -0
  109. package/dist/verifications/checkVerificationsNew.d.ts +1 -0
  110. package/dist/verifications/checkVerificationsNew.js +16 -0
  111. package/dist/verifications/cleanInstance.d.ts +9 -9
  112. package/dist/verifications/cleanInstance.js +15 -15
  113. package/dist/verifications/getOwnRealVerifications.d.ts +14 -0
  114. package/dist/verifications/getOwnRealVerifications.js +64 -0
  115. package/dist/verifications/getPOVerification.d.ts +16 -16
  116. package/dist/verifications/getPOVerification.js +94 -94
  117. package/dist/verifications/getRealVerifications.d.ts +22 -0
  118. package/dist/verifications/getRealVerifications.js +71 -0
  119. package/dist/verifications/getVerifiedBy.d.ts +1 -1
  120. package/dist/verifications/getVerifiedBy.js +19 -19
  121. package/dist/verifications/index.d.ts +5 -5
  122. package/dist/verifications/index.js +21 -17
  123. package/dist/verifications/maybeRereference.d.ts +1 -1
  124. package/dist/verifications/maybeRereference.js +10 -10
  125. package/dist/verifications/safeHarbour.d.ts +20 -20
  126. package/dist/verifications/safeHarbour.js +74 -74
  127. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -13
  128. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +64 -63
  129. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
  130. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -71
  131. package/dist/verifications/verifyCheck/index.d.ts +3 -3
  132. package/dist/verifications/verifyCheck/index.js +21 -17
  133. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -15
  134. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -39
  135. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -1
  136. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.js +16 -16
  137. package/dist/verifications/verifyCheck/operations/index.d.ts +2 -2
  138. package/dist/verifications/verifyCheck/operations/index.js +18 -14
  139. package/dist/verifications/verifyCheck/util/canonicalJsonify.d.ts +1 -0
  140. package/dist/verifications/verifyCheck/util/canonicalJsonify.js +48 -0
  141. package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +2 -0
  142. package/dist/verifications/verifyCheck/util/getValuesForAField.js +9 -0
  143. package/dist/verifications/verifyCheck/util/index.d.ts +2 -0
  144. package/dist/verifications/verifyCheck/util/index.js +14 -0
  145. package/package.json +6 -5
package/CHANGELOG.md ADDED
@@ -0,0 +1,161 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## 10.1.0 (2022-07-06)
11
+
12
+ - move `repairDate` into core, and use it when processing verifications
13
+
14
+ ## 10.0.1 (2022-07-06)
15
+
16
+ - added 2 methods (`isScoreResultValid` and `isScoreConfigValid`) to verify if stored score-data is valid
17
+
18
+ ## 10.0.0 (2022-04-11)
19
+
20
+ - 💥 BREAKING CHANGE: `calculateScore` is now an async function, and returns extra diagnostics.
21
+
22
+ ## 9.0.3 (2022-02-22)
23
+
24
+ - fixed a bug which caused valid live persons to show up as Not Verified.
25
+
26
+ ## 9.0.2 (2022-02-10)
27
+
28
+ - removed the `UNSAFE_treatNoValueAsVerified` option. This option was never documented or officially supported, so this is not considered a breaking change.
29
+ - use the `date_component` schema field tag in date-related code
30
+
31
+ ## 9.0.1 (2022-02-09)
32
+
33
+ - update `@raytio/types` to v6
34
+
35
+ ## 9.0.0 (2022-02-01)
36
+
37
+ - 💥 BREAKING CHANGE: the value returned by `getPOVerification` has changed slightly: the `details` property is now an object
38
+ - 💥 BREAKING CHANGE: `getRealVerifications` has been removed. It has been replaced by the following two methods:
39
+ - `getSomeoneElsesRealVerifications` is identical to the former `getRealVerifications` - it requires calling the API
40
+ - `getOwnRealVerifications` verifies the signature locally, but can only be used if you're verifying your own data.
41
+ - create the `calculateScore` and `convertInstanceToRuleInput` for working with SubmissionRules
42
+ - support 1 level of sub-fields in SubmissionRules
43
+ - 💥 BREAKING CHANGE: `getSomeoneElsesRealVerifications` now requires you to supply the `aId` of the submission
44
+
45
+ ## 8.1.3 (2021-10-05)
46
+
47
+ - published updated README.md
48
+
49
+ ## 8.1.2 (2021-09-24)
50
+
51
+ - update API format for `nId`s that start with `HASHED::`
52
+ - move `cleanInstance` to `@raytio/core`
53
+
54
+ ## 8.1.1 (2021-09-15)
55
+
56
+ - fix a bug with `nId`s that start with `HASHED::`
57
+
58
+ ## 8.1.0 (2021-08-31)
59
+
60
+ - update `getRealVerifications` to support `nId`s that start with `HASHED::`
61
+ - changed the behaviour of `isConditionMet` when the condition is an empty object. It now returns false in this case
62
+ - use new format for verify_check API
63
+
64
+ ## 8.0.0 (2021-07-28)
65
+
66
+ - support conditionally verifiable fields. This only works if the schema is processed by `processSchema`
67
+ - added `isConditionMet` to assit conditionally hidden/required/verifiable fields
68
+ - 💥 BREAKING CHANGE: `getPOVerification` no longer accepts `allSchema` and `schemaName` as an argument, this has been replaced with `schema`.
69
+ - 💥 BREAKING CHANGE: `calcSafeHarbourScore` is now async and no longer accepts `allSchema`, ths has been replaced with an argumnet called `getSchema`.
70
+
71
+ ## 7.0.0 (2021-04-07)
72
+
73
+ - 💥 BREAKING CHANGE: (TS) `POVerification` and `FieldVerification` are now enums, not string unions
74
+ - fixed a commonjs export bug in v6.0.1
75
+
76
+ ## 6.0.1 (2021-04-06)
77
+
78
+ - update `calcSafeHarbourScore` to ignore duplicate verifications
79
+
80
+ ## 6.0.0 (2021-03-05)
81
+
82
+ - 💥 BREAKING CHANGE: `decryptSharedData` now return `instance` and `applicationDecryptor`
83
+
84
+ ## 5.0.0 (2021-03-03)
85
+
86
+ - deps: upgrade maxcryptor to `0.3.0`
87
+ - 💥 BREAKING CHANGE: (TS) all IDs (e.g. `n_id`, `a_id`) now use nominal types (e.g. `NId`, `AId`)
88
+ - 💥 BREAKING CHANGE: require TypeScipt@4.2 or later
89
+
90
+ ## 4.0.1 (2021-02-05)
91
+
92
+ - fixed an npm publishing issue with `v4.0.0`
93
+
94
+ ## 4.0.0 (2021-02-04)
95
+
96
+ - 💥 BREAKING CHANGE: `LABELS_DENYLIST` is no longer exported. It was never documented and there should be no reason to use it. Use `findSchemaLabel` instead.
97
+ - 💥 BREAKING CHANGE: `createAA` should be supplied an `org_id` within the `application` attribute, not as a seperate attribute called `orgId`.
98
+ - 💥 BREAKING CHANGE: `decryptSharedData` no longer needs an `aId` attribute since it can get that information from the `instance` attribute. This isn't a breaking change per-se, but will cause type errors.
99
+ - use `unknown` instead of `any` in some predominantly internal types.
100
+
101
+ ## 3.2.2 (2021-01-19)
102
+
103
+ - reverted a bug fix from v3.2.1 which was a work-around for badly formatted data.
104
+
105
+ ## 3.2.1 (2021-01-18)
106
+
107
+ - fixed a bug where verified numbers weren't showing up as verified (reverted in v3.2.2)
108
+ - added `onCorruptedData` option to `decryptSharedData`
109
+
110
+ ## 3.2.0 (2021-01-06)
111
+
112
+ - added `toCognitoAttributes` and `fromCognitoAttributes`
113
+ - properly handle errors from all API requests
114
+
115
+ ## 3.1.0 (2020-12-19)
116
+
117
+ - add function to create an access application (`createAA`)
118
+
119
+ ## 3.0.0 (2020-12-17)
120
+
121
+ - 💥 BREAKING CHANGE: change safe harbour calculation to compare against a base person, instead of using relationships
122
+
123
+ ## 2.2.0 (2020-12-16)
124
+
125
+ - add Safe Harbour Compliance calculation (`calcSafeHarbourScore`)
126
+
127
+ ## 2.1.0 (2020-12-11)
128
+
129
+ - add a new type of [`FieldVerification`](https://www.npmjs.com/package/@raytio/types#fieldverification): `Expired`
130
+ - add a new type of [`POVerification`](https://www.npmjs.com/package/@raytio/types#poverification): `Expired`
131
+ - add a `expired` attribute to [`RealVer`](https://www.npmjs.com/package/@raytio/types#realver).
132
+ - update `getPOVerification` to return `Expired` for verifications where all fields are expired
133
+ - [internal] snapshot tests for auto generated documentation
134
+
135
+ ## 2.0.0 (2020-12-07)
136
+
137
+ - 💥 BREAKING CHANGE: support multiple verifications for the same data. This means that the `details` attribute returned by `getPOVerification` is now an array of [`VerificationProvider`](https://www.npmjs.com/package/@raytio/types#verificationprovider), instead of one [`VerificationProvider`](https://www.npmjs.com/package/@raytio/types#verificationprovider).
138
+
139
+ ## 1.0.4 (2020-12-06)
140
+
141
+ - fixed a bug where verification details were wrong if the same field name and value were verified by two sources
142
+ - include metadata from the verifier in `RealVer`s
143
+ - fix a bug where verifications for referenced files weren't working
144
+
145
+ ## 1.0.3 (2020-11-23)
146
+
147
+ - add `UNSAFE_treatNoValueAsVerified` option to getRealVerifications
148
+ - add `date` to `RealVer` type.
149
+
150
+ ## 1.0.2 (2020-11-20)
151
+
152
+ - `findSchemaLabel` can cope with it's argument being undefined.
153
+ - added `"receiverCreated"` to the list of internal labels
154
+
155
+ ## 1.0.1 (2020-11-18)
156
+
157
+ - `getRealVerifications` no longer requires an `apiToken` argument, since the API is available without authentication.
158
+
159
+ ## 1.0.0 (2020-11-11)
160
+
161
+ First stable release
package/README.md CHANGED
@@ -40,6 +40,9 @@ If you wish to use `@raytio/core` directly, an example of configuring polyfills
40
40
  - [isConditionMet](#isconditionmet)
41
41
  - [isEncrypted](#isencrypted)
42
42
  - [isEncryptedFile](#isencryptedfile)
43
+ - [isScoreConfigValid](#isscoreconfigvalid)
44
+ - [isScoreResultValid](#isscoreresultvalid)
45
+ - [repairDate](#repairdate)
43
46
  - [someEncrypted](#someencrypted)
44
47
  - [toCognitoAttributes](#tocognitoattributes)
45
48
 
@@ -95,7 +98,7 @@ ___
95
98
 
96
99
  ### calculateScore
97
100
 
98
- ▸ **calculateScore**(`ruleConfig`, `ruleInput`): `ScoreResult`
101
+ ▸ **calculateScore**(`ruleConfig`, `ruleInput`): `Promise`<`ScoreResult`\>
99
102
 
100
103
  the main function to calculate a score and category.
101
104
  Might throw an error.
@@ -109,7 +112,7 @@ Might throw an error.
109
112
 
110
113
  #### Returns
111
114
 
112
- `ScoreResult`
115
+ `Promise`<`ScoreResult`\>
113
116
 
114
117
  ___
115
118
 
@@ -280,7 +283,11 @@ the [Maxcryptor](https://npm.im/@raytio/maxcryptor)'s `ApplicationEncryptor`.
280
283
 
281
284
  | Name | Type |
282
285
  | :------ | :------ |
283
- | `__namedParameters` | `Arg` |
286
+ | `__namedParameters` | `Object` |
287
+ | `__namedParameters.aId` | `AId` |
288
+ | `__namedParameters.apiToken` | `string` |
289
+ | `__namedParameters.apiUrl` | `string` |
290
+ | `__namedParameters.maxcryptor` | `DataEncryptorI` |
284
291
 
285
292
  #### Returns
286
293
 
@@ -373,6 +380,8 @@ ___
373
380
 
374
381
  ▸ **hashPassword**(`password`): `Promise`<`string`\>
375
382
 
383
+ **`deprecated`** legacy feature, see #1252
384
+
376
385
  AWS Cognito never gets the raw password. We send them
377
386
  a hashed verison using PBKDF2 with SHA-256 and 10,000
378
387
  iterations.
@@ -396,7 +405,17 @@ ___
396
405
  ▸ `Const` **isConditionMet**(`condition`, `formValues`): `boolean`
397
406
 
398
407
  Checks all other form values in case any have a
399
- trigger value that makes this field requirted.
408
+ trigger value that makes this field required.
409
+
410
+ **`example`**
411
+ ```json
412
+ [
413
+ { "if": { "age": [17, 18], "city": ["Taupō"] } },
414
+ { "if": { "age": [19, 20] } }
415
+ ]
416
+ ```
417
+
418
+ This means `[(age=17 OR age=18) AND (city=Taupō)] OR [(age=19 OR age=20)]`
400
419
 
401
420
  #### Parameters
402
421
 
@@ -451,6 +470,60 @@ true or false depending on whether the input is an encrypted Raytio file
451
470
 
452
471
  ___
453
472
 
473
+ ### isScoreConfigValid
474
+
475
+ ▸ `Const` **isScoreConfigValid**(`x`): x is ScoreConfig
476
+
477
+ determines whether a `ScoreConfig` object is valid
478
+
479
+ #### Parameters
480
+
481
+ | Name | Type |
482
+ | :------ | :------ |
483
+ | `x` | `unknown` |
484
+
485
+ #### Returns
486
+
487
+ x is ScoreConfig
488
+
489
+ ___
490
+
491
+ ### isScoreResultValid
492
+
493
+ ▸ `Const` **isScoreResultValid**(`x`): x is ScoreResult
494
+
495
+ determines whether a `ScoreResult` object is valid
496
+
497
+ #### Parameters
498
+
499
+ | Name | Type |
500
+ | :------ | :------ |
501
+ | `x` | `unknown` |
502
+
503
+ #### Returns
504
+
505
+ x is ScoreResult
506
+
507
+ ___
508
+
509
+ ### repairDate
510
+
511
+ ▸ **repairDate**(`date`): `Date`
512
+
513
+ repairs broken ISO dates into valid JS date objects
514
+
515
+ #### Parameters
516
+
517
+ | Name | Type |
518
+ | :------ | :------ |
519
+ | `date` | `string` \| `Date` |
520
+
521
+ #### Returns
522
+
523
+ `Date`
524
+
525
+ ___
526
+
454
527
  ### someEncrypted
455
528
 
456
529
  ▸ `Const` **someEncrypted**<`T`, `K`\>(...`args`): `number`
@@ -1,17 +1,17 @@
1
- import type { Maxcryptor, UserDoc } from "@raytio/maxcryptor";
2
- import type { AA } from "@raytio/types";
3
- /**
4
- * Creates an Access Application and associated public+private keys.
5
- *
6
- * The user must be part of an organization, and you need to include the `orgId`.
7
- *
8
- * You must also supply an apiToken and an instance of the maxcryptor for that user,
9
- * as well as the `userDoc` data which is stored in the user's cognito attributes.
10
- */
11
- export declare function createAA({ apiUrl, apiToken, userDoc, maxcryptor, application, }: {
12
- apiUrl: string;
13
- apiToken: string;
14
- application: Omit<AA, "a_id">;
15
- userDoc: UserDoc;
16
- maxcryptor: Maxcryptor;
17
- }): Promise<AA>;
1
+ import type { Maxcryptor, UserDoc } from "@raytio/maxcryptor";
2
+ import type { AA } from "@raytio/types";
3
+ /**
4
+ * Creates an Access Application and associated public+private keys.
5
+ *
6
+ * The user must be part of an organization, and you need to include the `orgId`.
7
+ *
8
+ * You must also supply an apiToken and an instance of the maxcryptor for that user,
9
+ * as well as the `userDoc` data which is stored in the user's cognito attributes.
10
+ */
11
+ export declare function createAA({ apiUrl, apiToken, userDoc, maxcryptor, application, }: {
12
+ apiUrl: string;
13
+ apiToken: string;
14
+ application: Omit<AA, "a_id">;
15
+ userDoc: UserDoc;
16
+ maxcryptor: Maxcryptor;
17
+ }): Promise<AA>;
@@ -1,71 +1,71 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAA = void 0;
4
- const util_1 = require("../util");
5
- /** @internal */
6
- const createApplication = ({ apiUrl, apiToken, application, }) => fetch(`${apiUrl}/share/v2/access_application`, {
7
- method: "POST",
8
- body: JSON.stringify(application),
9
- headers: { Authorization: `Bearer ${apiToken}` },
10
- }).then(util_1.handleResponse);
11
- /** @internal */
12
- const createApplicationPublicKey = async ({ apiUrl, apiToken, aId, publicKey, }) => {
13
- const PO = await fetch(`${apiUrl}/share/v2/access_application/${aId}/public_key`, {
14
- method: "POST",
15
- body: JSON.stringify({ a_id: aId, key: publicKey }),
16
- headers: { Authorization: `Bearer ${apiToken}` },
17
- }).then(util_1.handleResponse);
18
- return { publicKeyNId: PO.n_id };
19
- };
20
- /** @internal */
21
- const createApplicationEncryptedPrivateKey = ({ apiUrl, apiToken, publicKeyNId, encryptedPrivateKey, }) => fetch(`${apiUrl}/share/v2/access_application/public_key/${publicKeyNId}/private_key`, {
22
- method: "POST",
23
- body: JSON.stringify({ n_id: publicKeyNId, key: encryptedPrivateKey }),
24
- headers: { Authorization: `Bearer ${apiToken}` },
25
- }).then(util_1.handleResponse);
26
- /** @internal */
27
- async function createApplicationEncryptor(userDoc, maxcryptor) {
28
- const applicationEncryptor = await maxcryptor.createApplicationEncryptor();
29
- // The exported public key should be available for everyone
30
- const publicKey = await applicationEncryptor.exportPublicKey();
31
- // Encrypt the private key for the current user
32
- const encryptedPrivateKey = await applicationEncryptor.encryptPrivateKey(userDoc.encryption_key_pair.public_key);
33
- return {
34
- applicationEncryptor,
35
- publicKey,
36
- encryptedPrivateKey,
37
- };
38
- }
39
- /**
40
- * Creates an Access Application and associated public+private keys.
41
- *
42
- * The user must be part of an organization, and you need to include the `orgId`.
43
- *
44
- * You must also supply an apiToken and an instance of the maxcryptor for that user,
45
- * as well as the `userDoc` data which is stored in the user's cognito attributes.
46
- */
47
- async function createAA({ apiUrl, apiToken, userDoc, maxcryptor, application, }) {
48
- if (!application.org_id) {
49
- throw new Error("Cannot create an AA without an org_id");
50
- }
51
- const newApp = await createApplication({
52
- apiUrl,
53
- apiToken,
54
- application,
55
- });
56
- const { publicKey, encryptedPrivateKey } = await createApplicationEncryptor(userDoc, maxcryptor);
57
- const { publicKeyNId } = await createApplicationPublicKey({
58
- apiUrl,
59
- apiToken,
60
- aId: newApp.a_id,
61
- publicKey,
62
- });
63
- await createApplicationEncryptedPrivateKey({
64
- apiUrl,
65
- apiToken,
66
- publicKeyNId,
67
- encryptedPrivateKey,
68
- });
69
- return newApp;
70
- }
71
- exports.createAA = createAA;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAA = void 0;
4
+ const util_1 = require("../util");
5
+ /** @internal */
6
+ const createApplication = ({ apiUrl, apiToken, application, }) => fetch(`${apiUrl}/share/v2/access_application`, {
7
+ method: "POST",
8
+ body: JSON.stringify(application),
9
+ headers: { Authorization: `Bearer ${apiToken}` },
10
+ }).then(util_1.handleResponse);
11
+ /** @internal */
12
+ const createApplicationPublicKey = async ({ apiUrl, apiToken, aId, publicKey, }) => {
13
+ const PO = await fetch(`${apiUrl}/share/v2/access_application/${aId}/public_key`, {
14
+ method: "POST",
15
+ body: JSON.stringify({ a_id: aId, key: publicKey }),
16
+ headers: { Authorization: `Bearer ${apiToken}` },
17
+ }).then(util_1.handleResponse);
18
+ return { publicKeyNId: PO.n_id };
19
+ };
20
+ /** @internal */
21
+ const createApplicationEncryptedPrivateKey = ({ apiUrl, apiToken, publicKeyNId, encryptedPrivateKey, }) => fetch(`${apiUrl}/share/v2/access_application/public_key/${publicKeyNId}/private_key`, {
22
+ method: "POST",
23
+ body: JSON.stringify({ n_id: publicKeyNId, key: encryptedPrivateKey }),
24
+ headers: { Authorization: `Bearer ${apiToken}` },
25
+ }).then(util_1.handleResponse);
26
+ /** @internal */
27
+ async function createApplicationEncryptor(userDoc, maxcryptor) {
28
+ const applicationEncryptor = await maxcryptor.createApplicationEncryptor();
29
+ // The exported public key should be available for everyone
30
+ const publicKey = await applicationEncryptor.exportPublicKey();
31
+ // Encrypt the private key for the current user
32
+ const encryptedPrivateKey = await applicationEncryptor.encryptPrivateKey(userDoc.encryption_key_pair.public_key);
33
+ return {
34
+ applicationEncryptor,
35
+ publicKey,
36
+ encryptedPrivateKey,
37
+ };
38
+ }
39
+ /**
40
+ * Creates an Access Application and associated public+private keys.
41
+ *
42
+ * The user must be part of an organization, and you need to include the `orgId`.
43
+ *
44
+ * You must also supply an apiToken and an instance of the maxcryptor for that user,
45
+ * as well as the `userDoc` data which is stored in the user's cognito attributes.
46
+ */
47
+ async function createAA({ apiUrl, apiToken, userDoc, maxcryptor, application, }) {
48
+ if (!application.org_id) {
49
+ throw new Error("Cannot create an AA without an org_id");
50
+ }
51
+ const newApp = await createApplication({
52
+ apiUrl,
53
+ apiToken,
54
+ application,
55
+ });
56
+ const { publicKey, encryptedPrivateKey } = await createApplicationEncryptor(userDoc, maxcryptor);
57
+ const { publicKeyNId } = await createApplicationPublicKey({
58
+ apiUrl,
59
+ apiToken,
60
+ aId: newApp.a_id,
61
+ publicKey,
62
+ });
63
+ await createApplicationEncryptedPrivateKey({
64
+ apiUrl,
65
+ apiToken,
66
+ publicKeyNId,
67
+ encryptedPrivateKey,
68
+ });
69
+ return newApp;
70
+ }
71
+ exports.createAA = createAA;
@@ -1 +1 @@
1
- export * from "./createAA";
1
+ export * from "./createAA";
@@ -1,13 +1,17 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./createAA"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./createAA"), exports);
@@ -1,15 +1,15 @@
1
- import { UserDoc } from "@raytio/maxcryptor";
2
- import type { ICognitoUserAttributeData } from "amazon-cognito-identity-js";
3
- /**
4
- * Given a `UserDoc` from the maxcryptor, this returns an object
5
- * which you can provide to `Auth.updateUserAttributes()`. It is
6
- * an object of stringified Json.
7
- */
8
- export declare const toCognitoAttributes: (userDoc: UserDoc) => {
9
- [customCognitoName: string]: string;
10
- };
11
- /**
12
- * This function converts Cognito's userAttributes into a maxcryptor UserDoc.
13
- * The userAttributes come from `const attributes = await Auth.userAttributes(user)`
14
- */
15
- export declare const fromCognitoAttributes: (attributes: ICognitoUserAttributeData[]) => UserDoc;
1
+ import { UserDoc } from "@raytio/maxcryptor";
2
+ import type { ICognitoUserAttributeData } from "amazon-cognito-identity-js";
3
+ /**
4
+ * Given a `UserDoc` from the maxcryptor, this returns an object
5
+ * which you can provide to `Auth.updateUserAttributes()`. It is
6
+ * an object of stringified Json.
7
+ */
8
+ export declare const toCognitoAttributes: (userDoc: UserDoc) => {
9
+ [customCognitoName: string]: string;
10
+ };
11
+ /**
12
+ * This function converts Cognito's userAttributes into a maxcryptor UserDoc.
13
+ * The userAttributes come from `const attributes = await Auth.userAttributes(user)`
14
+ */
15
+ export declare const fromCognitoAttributes: (attributes: ICognitoUserAttributeData[]) => UserDoc;
@@ -1,33 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fromCognitoAttributes = exports.toCognitoAttributes = void 0;
4
- const ramda_1 = require("ramda");
5
- const ATTRIBUTE_MAP = {
6
- "custom:kek_derivation": ["kek_derivation_config"],
7
- "custom:dek_encryption": ["private_key_encryption_config"],
8
- "custom:aek_public": ["encryption_key_pair", "public_key"],
9
- "custom:aek_private": ["encryption_key_pair", "private_key"],
10
- "custom:ask_public": ["signing_key_pair", "public_key"],
11
- "custom:ask_private": ["signing_key_pair", "private_key"],
12
- };
13
- /**
14
- * Given a `UserDoc` from the maxcryptor, this returns an object
15
- * which you can provide to `Auth.updateUserAttributes()`. It is
16
- * an object of stringified Json.
17
- */
18
- const toCognitoAttributes = (userDoc) => Object.fromEntries(Object.entries(ATTRIBUTE_MAP).map(([cognitoKey, deepPath]) => [
19
- cognitoKey,
20
- JSON.stringify((0, ramda_1.path)(deepPath, userDoc)),
21
- ]));
22
- exports.toCognitoAttributes = toCognitoAttributes;
23
- /**
24
- * This function converts Cognito's userAttributes into a maxcryptor UserDoc.
25
- * The userAttributes come from `const attributes = await Auth.userAttributes(user)`
26
- */
27
- const fromCognitoAttributes = (attributes) => attributes.reduce((ac, { Name, Value }) => {
28
- const maybePath = ATTRIBUTE_MAP[Name];
29
- if (!maybePath)
30
- return ac; // we don't know about this attribute
31
- return (0, ramda_1.assocPath)(maybePath, JSON.parse(Value), ac);
32
- }, {});
33
- exports.fromCognitoAttributes = fromCognitoAttributes;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fromCognitoAttributes = exports.toCognitoAttributes = void 0;
4
+ const ramda_1 = require("ramda");
5
+ const ATTRIBUTE_MAP = {
6
+ "custom:kek_derivation": ["kek_derivation_config"],
7
+ "custom:dek_encryption": ["private_key_encryption_config"],
8
+ "custom:aek_public": ["encryption_key_pair", "public_key"],
9
+ "custom:aek_private": ["encryption_key_pair", "private_key"],
10
+ "custom:ask_public": ["signing_key_pair", "public_key"],
11
+ "custom:ask_private": ["signing_key_pair", "private_key"],
12
+ };
13
+ /**
14
+ * Given a `UserDoc` from the maxcryptor, this returns an object
15
+ * which you can provide to `Auth.updateUserAttributes()`. It is
16
+ * an object of stringified Json.
17
+ */
18
+ const toCognitoAttributes = (userDoc) => Object.fromEntries(Object.entries(ATTRIBUTE_MAP).map(([cognitoKey, deepPath]) => [
19
+ cognitoKey,
20
+ JSON.stringify((0, ramda_1.path)(deepPath, userDoc)),
21
+ ]));
22
+ exports.toCognitoAttributes = toCognitoAttributes;
23
+ /**
24
+ * This function converts Cognito's userAttributes into a maxcryptor UserDoc.
25
+ * The userAttributes come from `const attributes = await Auth.userAttributes(user)`
26
+ */
27
+ const fromCognitoAttributes = (attributes) => attributes.reduce((ac, { Name, Value }) => {
28
+ const maybePath = ATTRIBUTE_MAP[Name];
29
+ if (!maybePath)
30
+ return ac; // we don't know about this attribute
31
+ return (0, ramda_1.assocPath)(maybePath, JSON.parse(Value), ac);
32
+ }, {});
33
+ exports.fromCognitoAttributes = fromCognitoAttributes;
@@ -1 +1 @@
1
- export {};
1
+ export {};