@binsky/passman-client-ts 0.1.9 → 0.2.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 (66) hide show
  1. package/README.md +12 -0
  2. package/lib/Interfaces/Credential/{CredentialInterface.d.ts → DecryptedCredentialInterface.d.ts} +5 -1
  3. package/lib/Interfaces/Credential/EncryptedCredentialInterface.d.ts +12 -11
  4. package/lib/Interfaces/Credential/EncryptedOwnedCredentialFromServerInterface.d.ts +35 -0
  5. package/lib/Interfaces/Credential/EncryptedOwnedCredentialFromServerInterface.js +2 -0
  6. package/lib/Interfaces/Credential/EncryptedOwnedCredentialToUpdateForServerInterface.d.ts +8 -0
  7. package/lib/Interfaces/Credential/EncryptedOwnedCredentialToUpdateForServerInterface.js +2 -0
  8. package/lib/Interfaces/Credential/OTPConfigInterface.d.ts +6 -1
  9. package/lib/Interfaces/Credential/OTPConfigInterface.js +6 -0
  10. package/lib/Interfaces/Credential/SerializableTransferCredentialInterface.d.ts +7 -0
  11. package/lib/Interfaces/Credential/SerializableTransferCredentialInterface.js +2 -0
  12. package/lib/Interfaces/DecryptedDataCachingHandlerInterface.d.ts +20 -0
  13. package/lib/Interfaces/DecryptedDataCachingHandlerInterface.js +2 -0
  14. package/lib/Interfaces/NextcloudServer/NextcloudServerInterface.d.ts +8 -3
  15. package/lib/Interfaces/PassmanCrypto/EncryptedStringType.d.ts +4 -0
  16. package/lib/Interfaces/PassmanCrypto/EncryptedStringType.js +2 -0
  17. package/lib/Interfaces/PersistenceInterface.d.ts +10 -0
  18. package/lib/Interfaces/PersistenceInterface.js +2 -0
  19. package/lib/Interfaces/RequestCachingHandlerInterface.d.ts +5 -1
  20. package/lib/Interfaces/Revision/RevisionInterface.d.ts +2 -2
  21. package/lib/Interfaces/ShareService/CredentialShareRequestInterface.d.ts +2 -2
  22. package/lib/Interfaces/ShareService/SerializableACLInterface.d.ts +14 -0
  23. package/lib/Interfaces/ShareService/SerializableACLInterface.js +2 -0
  24. package/lib/Interfaces/Vault/GenericVaultInformationFromServerInterface.d.ts +17 -0
  25. package/lib/Interfaces/Vault/GenericVaultInformationFromServerInterface.js +2 -0
  26. package/lib/Interfaces/Vault/SerializableSpecificVaultInformationFromServerInterface.d.ts +12 -0
  27. package/lib/Interfaces/Vault/SerializableSpecificVaultInformationFromServerInterface.js +2 -0
  28. package/lib/Interfaces/Vault/SerializableTransferFullVaultInterface.d.ts +6 -0
  29. package/lib/Interfaces/Vault/SerializableTransferFullVaultInterface.js +2 -0
  30. package/lib/Interfaces/Vault/SpecificVaultInformationFromServerInterface.d.ts +14 -0
  31. package/lib/Interfaces/Vault/SpecificVaultInformationFromServerInterface.js +2 -0
  32. package/lib/Interfaces/Vault/VaultCreateServerResponseInterface.d.ts +8 -0
  33. package/lib/Interfaces/Vault/VaultCreateServerResponseInterface.js +2 -0
  34. package/lib/Model/Credential.d.ts +70 -19
  35. package/lib/Model/Credential.js +138 -25
  36. package/lib/Model/File.d.ts +7 -7
  37. package/lib/Model/NextcloudServer.d.ts +9 -8
  38. package/lib/Model/NextcloudServer.js +14 -14
  39. package/lib/Model/PreloadedVault.d.ts +20 -0
  40. package/lib/Model/PreloadedVault.js +54 -0
  41. package/lib/Model/Revision.d.ts +3 -3
  42. package/lib/Model/Revision.js +3 -3
  43. package/lib/Model/SharingACL.d.ts +3 -2
  44. package/lib/Model/SharingACL.js +9 -6
  45. package/lib/Model/Vault.d.ts +48 -5
  46. package/lib/Model/Vault.js +141 -61
  47. package/lib/PassmanClient.d.ts +51 -10
  48. package/lib/PassmanClient.js +101 -35
  49. package/lib/Service/CredentialFilterService.d.ts +2 -1
  50. package/lib/Service/CredentialFilterService.js +24 -9
  51. package/lib/Service/CustomMathsService.js +1 -11
  52. package/lib/Service/DefaultLoggingService.d.ts +3 -0
  53. package/lib/Service/DefaultLoggingService.js +3 -0
  54. package/lib/Service/DefaultPersistenceService.d.ts +12 -0
  55. package/lib/Service/DefaultPersistenceService.js +20 -0
  56. package/lib/Service/OTPService.d.ts +6 -6
  57. package/lib/Service/OTPService.js +21 -8
  58. package/lib/Service/PassmanCrypto.d.ts +9 -4
  59. package/lib/Service/PassmanCrypto.js +6 -6
  60. package/lib/Service/ReEncryptionService.js +2 -2
  61. package/lib/Service/RequestCachingService.d.ts +5 -2
  62. package/lib/Service/RequestCachingService.js +3 -0
  63. package/lib/Service/ShareService.js +2 -4
  64. package/lib/tsconfig.tsbuildinfo +1 -1
  65. package/package.json +3 -1
  66. /package/lib/Interfaces/Credential/{CredentialInterface.js → DecryptedCredentialInterface.js} +0 -0
@@ -11,7 +11,7 @@ export declare enum FILTERS {
11
11
  ENCRYPTION_BROKEN = 7
12
12
  }
13
13
  export declare class CredentialFilterService {
14
- static getFilteredCredentials: (allCredentials: Credential[], filter: FILTERS, additionalFilterText?: string) => Credential[];
14
+ static getFilteredCredentials: (allCredentials: Credential[], filter: FILTERS, additionalFilterText?: string, additionalFilterTags?: string[]) => Credential[];
15
15
  static getFilterStats: (allCredentials: Credential[]) => FilterStatsInterface;
16
16
  static isHidden(credential: Credential): boolean;
17
17
  static isDeleted(credential: Credential): boolean;
@@ -21,4 +21,5 @@ export declare class CredentialFilterService {
21
21
  static hasMediumStrength(credential: Credential): boolean;
22
22
  static hasGoodStrength(credential: Credential): boolean;
23
23
  static matchesFilterText(credential: Credential, filterText: string): boolean;
24
+ static matchesFilterTags(credential: Credential, filterTags: string[]): boolean;
24
25
  }
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.CredentialFilterService = exports.FILTERS = void 0;
27
37
  const core_1 = require("@zxcvbn-ts/core");
@@ -39,7 +49,7 @@ var FILTERS;
39
49
  FILTERS[FILTERS["ENCRYPTION_BROKEN"] = 7] = "ENCRYPTION_BROKEN"; // use FILTERS.ENCRYPTION_BROKEN only when you really know what you are doing
40
50
  })(FILTERS || (exports.FILTERS = FILTERS = {}));
41
51
  class CredentialFilterService {
42
- static getFilteredCredentials = (allCredentials, filter, additionalFilterText = undefined) => {
52
+ static getFilteredCredentials = (allCredentials, filter, additionalFilterText = undefined, additionalFilterTags = undefined) => {
43
53
  let filtered = [];
44
54
  for (const credential of allCredentials) {
45
55
  if (filter === FILTERS.ENCRYPTION_BROKEN) {
@@ -55,8 +65,10 @@ class CredentialFilterService {
55
65
  continue;
56
66
  }
57
67
  const additionalTextFilterEnabled = additionalFilterText !== undefined && additionalFilterText !== '';
68
+ const additionalTagsFilterEnabled = additionalFilterTags !== undefined && additionalFilterTags.length > 0;
58
69
  // filter text if possible, otherwise ignore filter and proceed
59
- if (!additionalTextFilterEnabled || (additionalTextFilterEnabled && CredentialFilterService.matchesFilterText(credential, additionalFilterText))) {
70
+ if ((!additionalTextFilterEnabled || (additionalTextFilterEnabled && CredentialFilterService.matchesFilterText(credential, additionalFilterText))) &&
71
+ (!additionalTagsFilterEnabled || (additionalTagsFilterEnabled && CredentialFilterService.matchesFilterTags(credential, additionalFilterTags)))) {
60
72
  if (filter === FILTERS.DELETED) {
61
73
  // deleted credentials will not match any other category
62
74
  if (CredentialFilterService.isDeleted(credential)) {
@@ -205,5 +217,8 @@ class CredentialFilterService {
205
217
  }
206
218
  return false;
207
219
  }
220
+ static matchesFilterTags(credential, filterTags) {
221
+ return credential.tags && credential.tags.filter(tag => filterTags.includes(tag.text)).length > 0;
222
+ }
208
223
  }
209
224
  exports.CredentialFilterService = CredentialFilterService;
@@ -49,18 +49,8 @@ class CustomMathsService {
49
49
  const max_range = 256;
50
50
  const range = Math.min(max - min + 1, max_range);
51
51
  let randomNumber;
52
- let myCrypto = null;
53
- if (window && window.crypto) {
54
- myCrypto = window.crypto;
55
- }
56
- else if (crypto) {
57
- myCrypto = crypto;
58
- }
59
- else {
60
- return null;
61
- }
62
52
  do {
63
- myCrypto.getRandomValues(byteArray);
53
+ crypto.getRandomValues(byteArray);
64
54
  randomNumber = byteArray[0];
65
55
  } while (randomNumber >= Math.floor(max_range / range) * range);
66
56
  return min + (randomNumber % range);
@@ -1,4 +1,7 @@
1
1
  import type { LoggingHandlerInterface } from "../Interfaces/LoggingHandlerInterface";
2
+ /**
3
+ * Provides simple console logging.
4
+ */
2
5
  export declare class DefaultLoggingService implements LoggingHandlerInterface {
3
6
  onDebug(message: string): void;
4
7
  onInfo(message: string): void;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultLoggingService = void 0;
4
+ /**
5
+ * Provides simple console logging.
6
+ */
4
7
  class DefaultLoggingService {
5
8
  onDebug(message) {
6
9
  console.debug(message);
@@ -0,0 +1,12 @@
1
+ import { PersistenceInterface } from "../Interfaces/PersistenceInterface";
2
+ import { DecryptedDataCachingHandlerInterface } from "../Interfaces/DecryptedDataCachingHandlerInterface";
3
+ import { RequestCachingHandlerInterface } from "../Interfaces/RequestCachingHandlerInterface";
4
+ /**
5
+ * This default persistence service is useless and just a placeholder. It won't cache or persist anything!
6
+ */
7
+ export declare class DefaultPersistenceService implements PersistenceInterface {
8
+ constructor();
9
+ autoRestoreOnReconstruction(): boolean;
10
+ getDecryptedDataCacheHandler(): DecryptedDataCachingHandlerInterface;
11
+ getRequestCacheHandler(): RequestCachingHandlerInterface;
12
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultPersistenceService = void 0;
4
+ /**
5
+ * This default persistence service is useless and just a placeholder. It won't cache or persist anything!
6
+ */
7
+ class DefaultPersistenceService {
8
+ constructor() {
9
+ }
10
+ autoRestoreOnReconstruction() {
11
+ return false;
12
+ }
13
+ getDecryptedDataCacheHandler() {
14
+ return undefined;
15
+ }
16
+ getRequestCacheHandler() {
17
+ return undefined;
18
+ }
19
+ }
20
+ exports.DefaultPersistenceService = DefaultPersistenceService;
@@ -1,22 +1,22 @@
1
1
  import { Secret } from "otpauth";
2
2
  import { OTPConfigInterface } from "../Interfaces/Credential/OTPConfigInterface";
3
3
  export declare class OTPService {
4
- static mergeDefaultOTPConfig: (otp: OTPConfigInterface) => void;
5
- static getSecretString: (secret: undefined | string | Secret) => string | undefined;
6
- static getDataUrlFromCurrentOTPValues: (otp: OTPConfigInterface) => string;
4
+ static readonly mergeDefaultOTPConfig: (otp: OTPConfigInterface) => void;
5
+ static readonly getSecretString: (secret: undefined | string | Secret) => string | undefined;
6
+ static readonly getDataUrlFromCurrentOTPValues: (otp: OTPConfigInterface) => string;
7
7
  /**
8
8
  * Updates otp.qr_uri with a new QR code and data url based on the raw otp values.
9
9
  * @param otp
10
10
  */
11
- static updateQRFromCurrentOTPValues: (otp: OTPConfigInterface) => void;
11
+ static readonly updateQRFromCurrentOTPValues: (otp: OTPConfigInterface) => void;
12
12
  /**
13
13
  * Returns the current token of the given OTP configuration.
14
14
  * @param otp
15
15
  */
16
- static updateOTP: (otp: OTPConfigInterface) => string;
16
+ static readonly updateOTP: (otp: OTPConfigInterface) => string;
17
17
  /**
18
18
  * Parse input file asynchronous as QR code, extract the TOTP values and return the IOTPConfig, that's built from it.
19
19
  * @param input
20
20
  */
21
- static parseOTPQrCodeFromInputFileData: (input: string | File | any) => Promise<OTPConfigInterface>;
21
+ static readonly parseOTPQrCodeFromInputFileData: (input: string | File | any) => Promise<OTPConfigInterface>;
22
22
  }
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -30,6 +40,7 @@ exports.OTPService = void 0;
30
40
  const OTPAuth = __importStar(require("otpauth"));
31
41
  const qrcode_generator_1 = __importDefault(require("qrcode-generator"));
32
42
  const qrcode_parser_1 = __importDefault(require("qrcode-parser"));
43
+ const OTPConfigInterface_1 = require("../Interfaces/Credential/OTPConfigInterface");
33
44
  class OTPService {
34
45
  static mergeDefaultOTPConfig = (otp) => {
35
46
  const defaults = {
@@ -123,7 +134,9 @@ class OTPService {
123
134
  },
124
135
  issuer: uri.searchParams.get('issuer'),
125
136
  secret: uri.searchParams.get('secret'),
126
- algorithm: uri.searchParams.get('algorithm') ? uri.searchParams.get('algorithm') : "SHA1",
137
+ algorithm: uri.searchParams.get('algorithm') && OTPConfigInterface_1.OTPAlgorithms.includes(uri.searchParams.get('algorithm'))
138
+ ? uri.searchParams.get('algorithm')
139
+ : "SHA1",
127
140
  period: uri.searchParams.get('period') ? parseInt(uri.searchParams.get('period')) : 30,
128
141
  digits: uri.searchParams.get('digits') ? parseInt(uri.searchParams.get('digits')) : 6,
129
142
  };
@@ -2,9 +2,14 @@ import { GenerateKeypairResponseInterface } from "../Interfaces/PassmanCrypto/Ge
2
2
  import { RSAKeypairInterface } from "../Interfaces/PassmanCrypto/RSAKeypairInterface";
3
3
  import { PEMRSAKeypairInterface } from "../Interfaces/PassmanCrypto/PEMRSAKeypairInterface";
4
4
  export declare class PassmanCrypto {
5
- static generateRSAKeypair: (keyLength?: number) => Promise<GenerateKeypairResponseInterface>;
6
- static rsaKeyPairToPEM: (keypair: RSAKeypairInterface) => PEMRSAKeypairInterface;
5
+ static readonly generateRSAKeypair: (keyLength?: number) => Promise<GenerateKeypairResponseInterface>;
6
+ static readonly rsaKeyPairToPEM: (keypair: RSAKeypairInterface) => PEMRSAKeypairInterface;
7
7
  private static readonly sjcl_encryption_config;
8
- static encryptString: (plainText: string, key: string) => string;
9
- static decryptString: (b64EncCiphertext: string, key: string) => string;
8
+ static readonly encryptString: (plainText: string, key: string) => string;
9
+ /**
10
+ * @param b64EncCiphertext
11
+ * @param key
12
+ * @throws untyped sjcl exceptions
13
+ */
14
+ static readonly decryptString: (b64EncCiphertext: string, key: string) => string | never;
10
15
  }
@@ -45,14 +45,14 @@ class PassmanCrypto {
45
45
  const ct = sjcl_1.default.encrypt(key, plainText, PassmanCrypto.sjcl_encryption_config, rp);
46
46
  return js_base64_1.Base64.btoa(ct);
47
47
  };
48
+ /**
49
+ * @param b64EncCiphertext
50
+ * @param key
51
+ * @throws untyped sjcl exceptions
52
+ */
48
53
  static decryptString = (b64EncCiphertext, key) => {
49
54
  const ciphertext = js_base64_1.Base64.atob(b64EncCiphertext);
50
- try {
51
- return sjcl_1.default.decrypt(key, ciphertext);
52
- }
53
- catch (e) {
54
- throw e;
55
- }
55
+ return sjcl_1.default.decrypt(key, ciphertext);
56
56
  };
57
57
  }
58
58
  exports.PassmanCrypto = PassmanCrypto;
@@ -52,7 +52,7 @@ class ReEncryptionService {
52
52
  progressState.credentialsStage.totalSteps = originalCredentials.length;
53
53
  for (let i = 0; i < originalCredentials.length; i++) {
54
54
  progressState.credentialsStage.doneSteps = i;
55
- if (originalCredentials[i].sharedCredentialEncryptionKey) {
55
+ if (originalCredentials[i].encryptedSharedCredentialEncryptionKey) {
56
56
  // don't re-encrypt credentials that are shared with us
57
57
  progressState.credentialsStage.messages.push('Skip shared credential: ' + originalCredentials[i].label);
58
58
  onProgress(progressState);
@@ -109,7 +109,7 @@ class ReEncryptionService {
109
109
  if (revisions && revisions.length > 0) {
110
110
  for (let j = 0; j < revisions.length; j++) {
111
111
  try {
112
- const tmpCredential = await Revision_1.default.fromData(revisions[j].credential_data, vault, vault.getServer());
112
+ const tmpCredential = Revision_1.default.fromData(revisions[j].credential_data, vault, vault.getServer());
113
113
  revisions[j].credential_data = tmpCredential.reEncryptAsClone(newPassword).getEncrypted();
114
114
  revisionsToUpdateOnSuccess.push(revisions[j]);
115
115
  }
@@ -1,7 +1,10 @@
1
1
  import { RequestCachingHandlerInterface } from "../Interfaces/RequestCachingHandlerInterface";
2
+ /**
3
+ * Service to be used within a custom persistence instance, by providing custom get/set callbacks.
4
+ */
2
5
  export declare class RequestCachingService implements RequestCachingHandlerInterface {
3
- private onGetCallback;
4
- private onSetCallback;
6
+ private readonly onGetCallback;
7
+ private readonly onSetCallback;
5
8
  constructor(onGetCallback: (key: string) => string, onSetCallback: (key: string, value: string) => void);
6
9
  set(key: string, value: string): Promise<void>;
7
10
  get(key: string): Promise<string>;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RequestCachingService = void 0;
4
+ /**
5
+ * Service to be used within a custom persistence instance, by providing custom get/set callbacks.
6
+ */
4
7
  class RequestCachingService {
5
8
  onGetCallback;
6
9
  onSetCallback;
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ShareService = void 0;
7
7
  const Credential_1 = __importDefault(require("../Model/Credential"));
8
- const PassmanCrypto_1 = require("./PassmanCrypto");
9
8
  const SharingACL_1 = require("../Model/SharingACL");
10
9
  class ShareService {
11
10
  static async getCredentialsSharedWithUs(vault, server, getCachedIfPossible = false) {
@@ -16,9 +15,8 @@ class ShareService {
16
15
  if (sharedItemsResponse) {
17
16
  for (const sharedItem of sharedItemsResponse) {
18
17
  try {
19
- const decrypted_shared_key = PassmanCrypto_1.PassmanCrypto.decryptString(sharedItem.shared_key, vault.vaultKey);
20
- const sharedCredential = await Credential_1.default.fromData(sharedItem.credential_data, vault, server);
21
- sharedCredential.sharedCredentialEncryptionKey = decrypted_shared_key;
18
+ const sharedCredential = Credential_1.default.fromData(sharedItem.credential_data, vault, server);
19
+ sharedCredential.encryptedSharedCredentialEncryptionKey = sharedItem.shared_key;
22
20
  // transfer acl data from sharedItem into the new Credential object
23
21
  delete sharedItem.credential_data;
24
22
  const permissionsSharingAcl = new SharingACL_1.SharingACL(sharedItem.permissions);