@hive-p2p/browser 1.0.93 → 1.0.94

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.93",
3
+ "version": "1.0.94",
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 | Uint8Array} salt - Salt to use for the hash, in browser: string, in NodeJS: Uint8Array
20
+ * @param {string} salt - Salt to use for the hash
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
@@ -58,17 +58,17 @@ export class Argon2Unified {
58
58
  this.argon2 = argon2ES6.default;
59
59
  return this.argon2;
60
60
  };
61
- /** @param {string} pass @param {string | Uint8Array} salt @param {number} time @param {number} mem @param {number} parallelism @param {number} type @param {number} hashLen */
61
+ /** @param {string} pass @param {string} 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
- 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');
63
+ if (typeof salt !== 'string') throw new Error('salt must be a string');
65
64
 
66
- return { // If string salt: Pad/truncate to 16 characters
65
+ const s = salt.padEnd(64, '0').substring(0, 64); // 32 bytes = 64 hex chars, we ensure it's always 32 bytes by padding/truncating
66
+ return {
67
67
  type, pass, parallelism,
68
68
  time, timeCost: time, // we preserve both for compatibility
69
69
  mem, memoryCost: mem, // we preserve both for compatibility
70
70
  hashLen, hashLength: hashLen, // we preserve both for compatibility
71
- salt: IS_BROWSER ? salt.padEnd(16, '0').substring(0, 16) : Buffer.from(salt)
71
+ salt: IS_BROWSER ? s : Buffer.from(s)
72
72
  };
73
73
  }
74
74
  /** @param {string} encoded - Argon2 encoded string (e.g. $argon2id$v=19$m=1048576,t=1,p=1$c2FsdHNhbHRzYWx0c2FsdHNhbHQ$UamPN/XTTX4quPewQNw4/s3y1JJeS22cRroh5l7OTMM) */