@lumjs/encode 2.2.0 → 2.2.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.
package/CHANGELOG.md CHANGED
@@ -6,7 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- ## [2.2.0]
9
+ ## [2.2.2] - 2026-01-13
10
+ ### Fixed
11
+ - A few typos and bugs in the HMAC/HOTP/TOTP libraries I added last time.
12
+ - Added some missing timestamps in this changelog.
13
+ - Fixed references in this changelog.
14
+ ### Changed
15
+ - While fixing the broken bits, I made a bunch of previously hard-coded values
16
+ into options. They'll need to be properly documented at some point.
17
+ - Changed how `hash.getAlgorithm()` works behind the scenes.
18
+ - v2.2.1 never got published for reasons, so no log or tag for it.
19
+
20
+ ## [2.2.0] - 2025-11-18
10
21
  ### Added
11
22
  - intToBytes() and hexToBytes() functions added to util.js
12
23
  - A HMAC wrapper library, and a generic Signature class used by it.
@@ -16,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
16
27
  module, this one has two JS classes and uses the SubtleCrypto API.
17
28
  - A TODO file with things I want to do.
18
29
 
19
- ## [2.1.0]
30
+ ## [2.1.0] - 2025-90-09
20
31
  ### Changed
21
32
  - The `base64` library now supports the `Uint8Array.fromBase64` static method,
22
33
  and the corresponding `toBase64()` instance method. As those are rather new
@@ -52,7 +63,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
52
63
  ### Added
53
64
  - Initial release.
54
65
 
55
- [Unreleased]: https://github.com/supernovus/lum.encode.js/compare/v2.1.0...HEAD
66
+ [Unreleased]: https://github.com/supernovus/lum.encode.js/compare/v2.2.2...HEAD
67
+ [2.2.2]: https://github.com/supernovus/lum.encode.js/compare/v2.2.0...v2.2.2
68
+ [2.2.0]: https://github.com/supernovus/lum.encode.js/compare/v2.1.0...v2.2.0
56
69
  [2.1.0]: https://github.com/supernovus/lum.encode.js/compare/v2.0.0...v2.1.0
57
70
  [2.0.0]: https://github.com/supernovus/lum.encode.js/compare/v1.2.0...v2.0.0
58
71
  [1.2.0]: https://github.com/supernovus/lum.encode.js/compare/v1.1.0...v1.2.0
package/lib/hash.js CHANGED
@@ -27,6 +27,11 @@ const ALGO_INFO =
27
27
  'SHA-512': {length: 512, block: 1024},
28
28
  }
29
29
 
30
+ for (let algo in ALGO_INFO) {
31
+ ALGO_INFO[algo].id = algo;
32
+ Object.freeze(ALGO_INFO[algo]);
33
+ }
34
+
30
35
  const DATA_ENCODERS =
31
36
  {
32
37
  base64, base91,
@@ -184,7 +189,7 @@ module.exports = class
184
189
 
185
190
  if (id in ALGO_INFO)
186
191
  {
187
- return Object.assign({id}, ALGO_INFO[id]);
192
+ return ALGO_INFO[id];
188
193
  }
189
194
 
190
195
  // Invalid algorithm id, nothing to return.
@@ -299,8 +304,8 @@ module.exports = class
299
304
  async base64(input, opts=this.defaults.base64)
300
305
  {
301
306
  const hash = await this.hash(input);
302
- const b64str = base64.fromBytes(new Uint8Array(hash));
303
- return opts.url ? base64.urlize(b64str) : b64str;
307
+ const b64str = base64.fromBytes(new Uint8Array(hash), opts);
308
+ return opts.url ? base64.urlize(b64str, opts) : b64str;
304
309
  }
305
310
 
306
311
  /**
@@ -332,7 +337,7 @@ module.exports = class
332
337
 
333
338
  if (nba)
334
339
  {
335
- hash = util.numByteArray(hash);
340
+ hash = util.numByteArray(hash, nba);
336
341
  }
337
342
 
338
343
  return base91.encode(new Uint8Array(hash));
@@ -343,7 +348,7 @@ module.exports = class
343
348
  *
344
349
  * @param {(string|object)} input - A value to add to the hash.
345
350
  *
346
- * If it is an `object` then it will be processed with the `addWith`
351
+ * If it is an `object` then it will be processed with the `addUsing`
347
352
  * handler. See the constructor for details on supported formats.
348
353
  *
349
354
  * String values are simply added _as-is_.
package/lib/hmac.js CHANGED
@@ -2,8 +2,14 @@
2
2
 
3
3
  const Signature = require('./signature');
4
4
 
5
+ const CKEY = Symbol('@lumjs/encore/hmac~key');
5
6
  const HMAC = 'HMAC';
6
- const DEF_OPTS = { algorithm: 'SHA-256' };
7
+ const DEF_OPTS = {
8
+ algorithm: 'SHA-256',
9
+ extractable: false,
10
+ keyFormat: 'raw',
11
+ usages: ['sign']
12
+ };
7
13
 
8
14
  /**
9
15
  * The main class to perform HMAC signing.
@@ -31,20 +37,20 @@ class HmacEncoder {
31
37
  * @returns {Promise<CryptoKey>}
32
38
  */
33
39
  async getKey() {
34
- if (this._key) {
35
- return this._key;
40
+ if (this[CKEY]) {
41
+ return this[CKEY];
36
42
  }
37
43
 
38
44
  let hmac = { name: HMAC, hash: this.options.algorithm }
39
45
  let key = await crypto.subtle.importKey(
40
- "raw", // Key format
41
- this.keyBytes, // Key data
42
- hmac, // Algorithm
43
- false, // Not extractable
44
- ["sign"] // Usages
46
+ this.options.keyFormat, // Key format
47
+ this.keyBytes, // Key data
48
+ hmac, // Algorithm
49
+ this.options.extractable, // Is key extractable
50
+ this.options.usages, // Allowed key usages
45
51
  );
46
52
 
47
- this._key = key;
53
+ this[CKEY] = key;
48
54
  return key;
49
55
  }
50
56
 
package/lib/hotp.js CHANGED
@@ -3,7 +3,12 @@
3
3
  const HmacEncoder = require('./hmac');
4
4
  const { intToBytes } = require('./util');
5
5
 
6
- const DEF_OPTS = { algorithm: 'SHA-1', counter: 0, window: 50 };
6
+ const DEF_OPTS = {
7
+ algorithm: 'SHA-1',
8
+ checkSize: 7,
9
+ counter: 0,
10
+ window: 50
11
+ };
7
12
 
8
13
  const cp = Object.assign;
9
14
  const isError = v => (typeof v === 'function' && Error.isPrototypeOf(v));
@@ -62,7 +67,7 @@ class HOTP {
62
67
  (hb[offset + 3] & 0xff);
63
68
 
64
69
  let v2 = (v1 % 1000000) + '';
65
- let code = Array(LEN - v2.length).join('0') + v2;
70
+ let code = Array(opts.checkSize - v2.length).join('0') + v2;
66
71
 
67
72
  let res = {
68
73
  opts,
package/lib/index.js CHANGED
@@ -17,6 +17,7 @@ def(exports, 'util', {value: util}, E);
17
17
 
18
18
  /**
19
19
  * @alias module:@lumjs/encode.ord
20
+ * @deprecated this alias to `util.ord` will be removed in 3.x.
20
21
  * @see {@link module:@lumjs/encode/util.ord}
21
22
  */
22
23
  def(exports, 'ord', util.ord, E);
@@ -24,6 +25,7 @@ def(exports, 'ord', util.ord, E);
24
25
  /**
25
26
  * @name module:@lumjs/encode.numByteArray
26
27
  * @function
28
+ * @deprecated this alias to `util.numByteArray` will be removed in 3.x.
27
29
  * @see {@link module:@lumjs/encode/util.numByteArray}
28
30
  */
29
31
  def(exports, 'numByteArray', util.numByteArray, E);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumjs/encode",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "main": "lib/index.js",
5
5
  "exports":
6
6
  {