@hive-p2p/browser 1.0.91 → 1.0.93

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hive-p2p/browser",
3
- "version": "1.0.91",
3
+ "version": "1.0.93",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -17,7 +17,7 @@ export class Argon2Unified {
17
17
 
18
18
  /** This function hashes a password using Argon2 - Browser/NodeJS unified
19
19
  * @param {string} pass - Password to hash
20
- * @param {string} salt - Salt to use for the hash
20
+ * @param {string | Uint8Array} salt - Salt to use for the hash, in browser: string, in NodeJS: Uint8Array
21
21
  * @param {number} [mem] - Memory usage in KiB, default: 2**16 = 65_536 (64 MiB) | RECOMMENDED: 2**16
22
22
  * @param {number} [time] - Time cost in iterations, default: 1
23
23
  * @param {number} [parallelism] - Number of threads to use, default: 1
@@ -60,13 +60,15 @@ export class Argon2Unified {
60
60
  };
61
61
  /** @param {string} pass @param {string | Uint8Array} salt @param {number} time @param {number} mem @param {number} parallelism @param {number} type @param {number} hashLen */
62
62
  #createArgon2Params(pass = "averylongpassword123456", salt = "saltsaltsaltsaltsalt", time = 1, mem = 2**10, parallelism = 1, type = 2, hashLen = 32) {
63
- const fixedSalt = salt.padEnd(16, '0').substring(0, 16); // 32 bytes minimum
64
- return {
63
+ if (IS_BROWSER && typeof salt !== 'string') throw new Error('In browser, salt must be a string');
64
+ if (!IS_BROWSER && !(salt instanceof Uint8Array)) throw new Error('In NodeJS, salt must be a Uint8Array');
65
+
66
+ return { // If string salt: Pad/truncate to 16 characters
65
67
  type, pass, parallelism,
66
68
  time, timeCost: time, // we preserve both for compatibility
67
69
  mem, memoryCost: mem, // we preserve both for compatibility
68
70
  hashLen, hashLength: hashLen, // we preserve both for compatibility
69
- salt: IS_BROWSER ? fixedSalt : Buffer.from(fixedSalt),
71
+ salt: IS_BROWSER ? salt.padEnd(16, '0').substring(0, 16) : Buffer.from(salt)
70
72
  };
71
73
  }
72
74
  /** @param {string} encoded - Argon2 encoded string (e.g. $argon2id$v=19$m=1048576,t=1,p=1$c2FsdHNhbHRzYWx0c2FsdHNhbHQ$UamPN/XTTX4quPewQNw4/s3y1JJeS22cRroh5l7OTMM) */