@sudoplatform/sudo-common 5.10.0 → 6.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 (160) hide show
  1. package/.eslintrc.js +2 -4
  2. package/bin/outdated-with-suppression.sh +20 -0
  3. package/bin/suppress-outdated.sh +15 -0
  4. package/dependencies-report.json +1 -1
  5. package/docs/assets/search.js +1 -1
  6. package/docs/classes/AccountLockedError.html +4 -3
  7. package/docs/classes/AuthenticationError.html +4 -3
  8. package/docs/classes/Base64.html +2 -2
  9. package/docs/classes/Buffer.html +2 -2
  10. package/docs/classes/ConfigurationNotSetError.html +4 -3
  11. package/docs/classes/ConfigurationSetNotFoundError.html +4 -3
  12. package/docs/classes/DecodeError.html +4 -3
  13. package/docs/classes/DefaultConfigurationManager.html +6 -6
  14. package/docs/classes/DefaultLogger.html +7 -7
  15. package/docs/classes/DefaultSudoKeyArchive.html +13 -13
  16. package/docs/classes/DefaultSudoKeyManager.html +31 -27
  17. package/docs/classes/FatalError.html +4 -3
  18. package/docs/classes/IllegalArgumentError.html +4 -3
  19. package/docs/classes/IllegalStateError.html +4 -3
  20. package/docs/classes/InsufficientEntitlementsError.html +4 -3
  21. package/docs/classes/InvalidOwnershipProofError.html +4 -3
  22. package/docs/classes/InvalidTokenError.html +4 -3
  23. package/docs/classes/KeyArchiveDecodingError.html +4 -3
  24. package/docs/classes/KeyArchiveIncorrectPasswordError.html +4 -3
  25. package/docs/classes/KeyArchiveMissingError.html +4 -3
  26. package/docs/classes/KeyArchiveNoPasswordRequiredError.html +4 -3
  27. package/docs/classes/KeyArchivePasswordRequiredError.html +4 -3
  28. package/docs/classes/KeyArchiveTypeError.html +4 -3
  29. package/docs/classes/KeyArchiveUnknownKeyTypeError.html +4 -3
  30. package/docs/classes/KeyArchiveVersionError.html +4 -3
  31. package/docs/classes/KeyNotFoundError.html +4 -3
  32. package/docs/classes/KeyStoreNotExportableError.html +4 -3
  33. package/docs/classes/LimitExceededError.html +4 -3
  34. package/docs/classes/NoEntitlementsError.html +4 -3
  35. package/docs/classes/NotAuthorizedError.html +4 -3
  36. package/docs/classes/NotRegisteredError.html +4 -3
  37. package/docs/classes/NotSignedInError.html +4 -3
  38. package/docs/classes/OperationNotImplementedError.html +4 -3
  39. package/docs/classes/RegisterError.html +4 -3
  40. package/docs/classes/RequestFailedError.html +6 -5
  41. package/docs/classes/ServiceError.html +4 -3
  42. package/docs/classes/SignOutError.html +4 -3
  43. package/docs/classes/SudoCryptoProviderDefaults.html +1 -1
  44. package/docs/classes/UnknownGraphQLError.html +6 -4
  45. package/docs/classes/UnrecognizedAlgorithmError.html +4 -3
  46. package/docs/classes/UserNotConfirmedError.html +4 -3
  47. package/docs/classes/VersionMismatchError.html +4 -3
  48. package/docs/enums/CachePolicy.html +2 -2
  49. package/docs/enums/EncryptionAlgorithm.html +2 -2
  50. package/docs/enums/KeyArchiveKeyType.html +2 -2
  51. package/docs/enums/KeyDataKeyFormat.html +3 -3
  52. package/docs/enums/KeyDataKeyType.html +2 -2
  53. package/docs/enums/ListOperationResultStatus.html +4 -4
  54. package/docs/enums/PublicKeyFormat.html +1 -1
  55. package/docs/index.html +1 -1
  56. package/docs/interfaces/AsymmetricEncryptionOptions.html +2 -2
  57. package/docs/interfaces/BooleanFilter.html +2 -2
  58. package/docs/interfaces/ConfigurationManager.html +5 -5
  59. package/docs/interfaces/KeyData.html +2 -2
  60. package/docs/interfaces/ListOperationFailureResult.html +2 -2
  61. package/docs/interfaces/ListOperationPartialResult.html +4 -4
  62. package/docs/interfaces/ListOperationSuccessResult.html +3 -3
  63. package/docs/interfaces/ListOutput.html +2 -2
  64. package/docs/interfaces/Logger.html +7 -7
  65. package/docs/interfaces/Owner.html +1 -1
  66. package/docs/interfaces/PublicKey.html +1 -1
  67. package/docs/interfaces/StringFilter.html +2 -2
  68. package/docs/interfaces/SudoCryptoProvider.html +39 -31
  69. package/docs/interfaces/SudoKeyArchive.html +10 -10
  70. package/docs/interfaces/SudoKeyManager.html +39 -31
  71. package/docs/interfaces/SymmetricEncryptionOptions.html +2 -2
  72. package/docs/modules.html +4 -4
  73. package/github/.eslintrc.js +2 -4
  74. package/github/bin/outdated-with-suppression.sh +20 -0
  75. package/github/bin/suppress-outdated.sh +15 -0
  76. package/github/docs/assets/search.js +1 -1
  77. package/github/docs/classes/AccountLockedError.html +4 -3
  78. package/github/docs/classes/AuthenticationError.html +4 -3
  79. package/github/docs/classes/Base64.html +2 -2
  80. package/github/docs/classes/Buffer.html +2 -2
  81. package/github/docs/classes/ConfigurationNotSetError.html +4 -3
  82. package/github/docs/classes/ConfigurationSetNotFoundError.html +4 -3
  83. package/github/docs/classes/DecodeError.html +4 -3
  84. package/github/docs/classes/DefaultConfigurationManager.html +6 -6
  85. package/github/docs/classes/DefaultLogger.html +7 -7
  86. package/github/docs/classes/DefaultSudoKeyArchive.html +13 -13
  87. package/github/docs/classes/DefaultSudoKeyManager.html +31 -27
  88. package/github/docs/classes/FatalError.html +4 -3
  89. package/github/docs/classes/IllegalArgumentError.html +4 -3
  90. package/github/docs/classes/IllegalStateError.html +4 -3
  91. package/github/docs/classes/InsufficientEntitlementsError.html +4 -3
  92. package/github/docs/classes/InvalidOwnershipProofError.html +4 -3
  93. package/github/docs/classes/InvalidTokenError.html +4 -3
  94. package/github/docs/classes/KeyArchiveDecodingError.html +4 -3
  95. package/github/docs/classes/KeyArchiveIncorrectPasswordError.html +4 -3
  96. package/github/docs/classes/KeyArchiveMissingError.html +4 -3
  97. package/github/docs/classes/KeyArchiveNoPasswordRequiredError.html +4 -3
  98. package/github/docs/classes/KeyArchivePasswordRequiredError.html +4 -3
  99. package/github/docs/classes/KeyArchiveTypeError.html +4 -3
  100. package/github/docs/classes/KeyArchiveUnknownKeyTypeError.html +4 -3
  101. package/github/docs/classes/KeyArchiveVersionError.html +4 -3
  102. package/github/docs/classes/KeyNotFoundError.html +4 -3
  103. package/github/docs/classes/KeyStoreNotExportableError.html +4 -3
  104. package/github/docs/classes/LimitExceededError.html +4 -3
  105. package/github/docs/classes/NoEntitlementsError.html +4 -3
  106. package/github/docs/classes/NotAuthorizedError.html +4 -3
  107. package/github/docs/classes/NotRegisteredError.html +4 -3
  108. package/github/docs/classes/NotSignedInError.html +4 -3
  109. package/github/docs/classes/OperationNotImplementedError.html +4 -3
  110. package/github/docs/classes/RegisterError.html +4 -3
  111. package/github/docs/classes/RequestFailedError.html +6 -5
  112. package/github/docs/classes/ServiceError.html +4 -3
  113. package/github/docs/classes/SignOutError.html +4 -3
  114. package/github/docs/classes/SudoCryptoProviderDefaults.html +1 -1
  115. package/github/docs/classes/UnknownGraphQLError.html +6 -4
  116. package/github/docs/classes/UnrecognizedAlgorithmError.html +4 -3
  117. package/github/docs/classes/UserNotConfirmedError.html +4 -3
  118. package/github/docs/classes/VersionMismatchError.html +4 -3
  119. package/github/docs/enums/CachePolicy.html +2 -2
  120. package/github/docs/enums/EncryptionAlgorithm.html +2 -2
  121. package/github/docs/enums/KeyArchiveKeyType.html +2 -2
  122. package/github/docs/enums/KeyDataKeyFormat.html +3 -3
  123. package/github/docs/enums/KeyDataKeyType.html +2 -2
  124. package/github/docs/enums/ListOperationResultStatus.html +4 -4
  125. package/github/docs/enums/PublicKeyFormat.html +1 -1
  126. package/github/docs/index.html +1 -1
  127. package/github/docs/interfaces/AsymmetricEncryptionOptions.html +2 -2
  128. package/github/docs/interfaces/BooleanFilter.html +2 -2
  129. package/github/docs/interfaces/ConfigurationManager.html +5 -5
  130. package/github/docs/interfaces/KeyData.html +2 -2
  131. package/github/docs/interfaces/ListOperationFailureResult.html +2 -2
  132. package/github/docs/interfaces/ListOperationPartialResult.html +4 -4
  133. package/github/docs/interfaces/ListOperationSuccessResult.html +3 -3
  134. package/github/docs/interfaces/ListOutput.html +2 -2
  135. package/github/docs/interfaces/Logger.html +7 -7
  136. package/github/docs/interfaces/Owner.html +1 -1
  137. package/github/docs/interfaces/PublicKey.html +1 -1
  138. package/github/docs/interfaces/StringFilter.html +2 -2
  139. package/github/docs/interfaces/SudoCryptoProvider.html +39 -31
  140. package/github/docs/interfaces/SudoKeyArchive.html +10 -10
  141. package/github/docs/interfaces/SudoKeyManager.html +39 -31
  142. package/github/docs/interfaces/SymmetricEncryptionOptions.html +2 -2
  143. package/github/docs/modules.html +4 -4
  144. package/github/package.json +13 -10
  145. package/github/src/errors/error.ts +17 -8
  146. package/github/src/sudoKeyManager/sudoCryptoProvider.ts +14 -0
  147. package/github/src/sudoKeyManager/sudoKeyManager.ts +22 -0
  148. package/github/test/sudoKeyManager/sudoKeyManager.spec.ts +37 -0
  149. package/github/yarn.lock +566 -687
  150. package/lib/errors/error.d.ts +3 -2
  151. package/lib/errors/error.js +30 -20
  152. package/lib/sudoKeyManager/sudoCryptoProvider.d.ts +12 -0
  153. package/lib/sudoKeyManager/sudoKeyManager.d.ts +14 -0
  154. package/lib/sudoKeyManager/sudoKeyManager.js +8 -0
  155. package/package.json +13 -10
  156. package/src/errors/error.ts +17 -8
  157. package/src/sudoKeyManager/sudoCryptoProvider.ts +14 -0
  158. package/src/sudoKeyManager/sudoKeyManager.ts +22 -0
  159. package/test/sudoKeyManager/sudoKeyManager.spec.ts +37 -0
  160. package/yarn.lock +566 -687
@@ -9,6 +9,7 @@
9
9
  "license": "Apache-2.0",
10
10
  "scripts": {
11
11
  "audit-with-suppressions": "bin/yarn-audit-with-suppression.sh",
12
+ "outdated-with-suppressions": "bin/outdated-with-suppression.sh",
12
13
  "clean": "rimraf ./lib ./test-lib",
13
14
  "lint": "yarn lint:eslint && yarn lint:prettier",
14
15
  "lint:eslint": "eslint \"{bin,integration-tests,src,test}/**/*.{ts,tsx}\"",
@@ -24,7 +25,9 @@
24
25
  "types": "./lib/index.d.ts",
25
26
  "bin": {
26
27
  "audit-with-suppressions": "bin/yarn-audit-with-suppression.sh",
27
- "suppress-audit": "bin/suppress-audit.sh"
28
+ "suppress-audit": "bin/suppress-audit.sh",
29
+ "outdated-with-suppressions": "bin/outdated-with-suppression.sh",
30
+ "suppress-outdated": "bin/suppress-outdated.sh"
28
31
  },
29
32
  "files": [
30
33
  "lib",
@@ -53,23 +56,23 @@
53
56
  "@babel/preset-env": "^7.15.8",
54
57
  "@babel/preset-typescript": "^7.15.0",
55
58
  "@types/jest": "^27.0.2",
56
- "@typescript-eslint/eslint-plugin": "^4.33.0",
57
- "@typescript-eslint/parser": "^4.33.0",
58
- "eslint": "^7.32.0",
59
+ "@typescript-eslint/eslint-plugin": "^5.1.0",
60
+ "@typescript-eslint/parser": "^5.1.0",
61
+ "eslint": "^8.0.1",
59
62
  "eslint-config-prettier": "^8.3.0",
60
- "eslint-plugin-import": "^2.24.2",
63
+ "eslint-plugin-import": "^2.25.2",
61
64
  "eslint-plugin-prettier": "^4.0.0",
62
- "fp-ts": "^2.11.4",
65
+ "fp-ts": "^2.11.5",
63
66
  "io-ts": "^2.2.16",
64
67
  "io-ts-types": "^0.5.16",
65
68
  "isomorphic-webcrypto": "^2.3.8",
66
- "jest": "^27.2.4",
69
+ "jest": "^27.3.1",
67
70
  "monocle-ts": "^2.3.11",
68
71
  "newtype-ts": "^0.3.2",
69
72
  "prettier": "^2.4.1",
70
73
  "rimraf": "^3.0.2",
71
74
  "ts-mockito": "^2.6.1",
72
- "typedoc": "^0.22.5",
73
- "typescript": "^4.4.3"
75
+ "typedoc": "^0.22.6",
76
+ "typescript": "^4.4.4"
74
77
  }
75
- }
78
+ }
@@ -16,16 +16,25 @@ export function isAppSyncNetworkError(u: Error): u is AppSyncNetworkError {
16
16
  }
17
17
 
18
18
  /**
19
- * Indicates the GraphQL API returned an error that's not recognized by the client.
19
+ * Indicates the GraphQL API returned an error that's not recognized by
20
+ * the client.
20
21
  */
21
22
  export class UnknownGraphQLError extends Error {
22
- constructor(cause: AppSyncError) {
23
- super(
24
- `type: ${cause.errorType ?? '<cause type not specified>'}, message: ${
25
- cause.message
26
- }`,
27
- )
28
- this.name = 'GraphQLError'
23
+ constructor(cause: unknown) {
24
+ const maybeAppSyncError = cause as AppSyncError
25
+ let message: string
26
+ if (maybeAppSyncError?.errorType) {
27
+ message = `type: ${maybeAppSyncError.errorType}, message: ${maybeAppSyncError.message}`
28
+ } else if (maybeAppSyncError?.message) {
29
+ message = maybeAppSyncError?.message
30
+ } else if (maybeAppSyncError?.name) {
31
+ message = maybeAppSyncError.name
32
+ } else {
33
+ message = 'unknown cause'
34
+ }
35
+ super(message)
36
+
37
+ this.name = 'UnknownGraphQLError'
29
38
  }
30
39
  }
31
40
 
@@ -85,6 +85,13 @@ export interface SudoCryptoProvider {
85
85
  */
86
86
  getSymmetricKey(name: string): Promise<ArrayBuffer | undefined>
87
87
 
88
+ /**
89
+ * Checks to see if the specified symmetric key exists.
90
+ *
91
+ * @param name The name of the symmetric key.
92
+ */
93
+ doesSymmetricKeyExists(name: string): Promise<boolean>
94
+
88
95
  /**
89
96
  * Deletes a symmetric key from the secure store.
90
97
  *
@@ -147,6 +154,13 @@ export interface SudoCryptoProvider {
147
154
  */
148
155
  getPrivateKey(name: string): Promise<ArrayBuffer | undefined>
149
156
 
157
+ /**
158
+ * Checks to see if the specified private key exists.
159
+ *
160
+ * @param name The name of the private key.
161
+ */
162
+ doesPrivateKeyExists(name: string): Promise<boolean>
163
+
150
164
  /**
151
165
  * Adds a public key to the secure store.
152
166
  *
@@ -63,6 +63,13 @@ export interface SudoKeyManager {
63
63
  */
64
64
  getSymmetricKey(name: string): Promise<ArrayBuffer | undefined>
65
65
 
66
+ /**
67
+ * Checks to see if the specified symmetric key exists.
68
+ *
69
+ * @param name The name of the symmetric key.
70
+ */
71
+ doesSymmetricKeyExists(name: string): Promise<boolean>
72
+
66
73
  /**
67
74
  * Deletes a symmetric key from the secure store.
68
75
  *
@@ -87,6 +94,13 @@ export interface SudoKeyManager {
87
94
  */
88
95
  getPrivateKey(name: string): Promise<ArrayBuffer | undefined>
89
96
 
97
+ /**
98
+ * Checks to see if the specified private key exists.
99
+ *
100
+ * @param name The name of the private key.
101
+ */
102
+ doesPrivateKeyExists(name: string): Promise<boolean>
103
+
90
104
  /**
91
105
  * Adds a public key to the secure store.
92
106
  *
@@ -379,6 +393,10 @@ export class DefaultSudoKeyManager implements SudoKeyManager {
379
393
  return this.sudoCryptoProvider.getSymmetricKey(name)
380
394
  }
381
395
 
396
+ public doesSymmetricKeyExists(name: string): Promise<boolean> {
397
+ return this.sudoCryptoProvider.doesSymmetricKeyExists(name)
398
+ }
399
+
382
400
  public deleteSymmetricKey(name: string): Promise<void> {
383
401
  return this.sudoCryptoProvider.deleteSymmetricKey(name)
384
402
  }
@@ -395,6 +413,10 @@ export class DefaultSudoKeyManager implements SudoKeyManager {
395
413
  return this.sudoCryptoProvider.getPrivateKey(name)
396
414
  }
397
415
 
416
+ public doesPrivateKeyExists(name: string): Promise<boolean> {
417
+ return this.sudoCryptoProvider.doesPrivateKeyExists(name)
418
+ }
419
+
398
420
  public addPublicKey(key: ArrayBuffer, name: string): Promise<void> {
399
421
  return this.sudoCryptoProvider.addPublicKey(key, name)
400
422
  }
@@ -177,6 +177,24 @@ describe('DefaultSudoKeyManager', () => {
177
177
  })
178
178
  })
179
179
 
180
+ describe('doesSymmetricKeyExists', () => {
181
+ it('should call crypto provider doesSymmetricKeyExists', async () => {
182
+ when(
183
+ sudoCryptoProviderMock.doesSymmetricKeyExists(anything()),
184
+ ).thenResolve(true)
185
+
186
+ await expect(
187
+ sudoKeyManager.doesSymmetricKeyExists('VpnKey'),
188
+ ).resolves.toEqual(true)
189
+ const [actualKey] = capture(
190
+ sudoCryptoProviderMock.doesSymmetricKeyExists,
191
+ ).first()
192
+ expect(actualKey).toStrictEqual('VpnKey')
193
+
194
+ verify(sudoCryptoProviderMock.doesSymmetricKeyExists(anything())).once()
195
+ })
196
+ })
197
+
180
198
  describe('deleteSymmetricKey', () => {
181
199
  it('should call crypto provider deleteSymmetricKey', async () => {
182
200
  when(sudoCryptoProviderMock.deleteSymmetricKey(anything())).thenResolve()
@@ -263,6 +281,25 @@ describe('DefaultSudoKeyManager', () => {
263
281
  })
264
282
  })
265
283
 
284
+ describe('doesPrivateKeyExists', () => {
285
+ it('should call crypto provider doesPrivateKeyExists', async () => {
286
+ when(sudoCryptoProviderMock.doesPrivateKeyExists(anything())).thenResolve(
287
+ true,
288
+ )
289
+
290
+ await expect(
291
+ sudoKeyManager.doesPrivateKeyExists('VpnKeyPair'),
292
+ ).resolves.toBeTruthy()
293
+
294
+ const [actualKeyName] = capture(
295
+ sudoCryptoProviderMock.doesPrivateKeyExists,
296
+ ).first()
297
+ expect(actualKeyName).toStrictEqual('VpnKeyPair')
298
+
299
+ verify(sudoCryptoProviderMock.doesPrivateKeyExists(anything())).once()
300
+ })
301
+ })
302
+
266
303
  describe('addPublicKey', () => {
267
304
  it('should call crypto provider addPublicKey', async () => {
268
305
  when(