functionalscript 0.0.304 → 0.0.305

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": "functionalscript",
3
- "version": "0.0.304",
3
+ "version": "0.0.305",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/sha2/index.js CHANGED
@@ -12,7 +12,7 @@ const array = require('../types/array')
12
12
  /** @typedef {array.Array16<number>} Array16 */
13
13
 
14
14
  /** @type {(input: number) => (pos: number) => number} */
15
- const appendOne = input => pos => input | (1 << 31 - pos)
15
+ const appendOneWithZeros = input => pos => (input >> pos << pos) | (1 << pos)
16
16
 
17
17
  /** @type {(input: number) => (pos: number) => number} */
18
18
  const mod = a => b => (a % b + b) % b
@@ -26,7 +26,7 @@ const padding = input => bitsCount => {
26
26
  i < appendBlockIndex ?
27
27
  input[i] :
28
28
  i === appendBlockIndex ?
29
- (appendBlockIndex >= input.length ? 0x8000_0000 : appendOne(input[appendBlockIndex])(bitsCount % 32)) :
29
+ (appendBlockIndex >= input.length ? 0x8000_0000 : appendOneWithZeros(input[appendBlockIndex])(31 - bitsCount % 32)) :
30
30
  i === length - 2 ?
31
31
  (bitsCount / 0x1_0000_0000) | 0 :
32
32
  i === length - 1 ?
package/sha2/test.js CHANGED
@@ -51,6 +51,13 @@ const stringify = a => json.stringify(sort)(a)
51
51
  if (result !== '["b94d27b9","934d3e08","a52e52d7","da7dabfa","c484efe3","7a5380ee","9088f7ac","e2efcde9"]') { throw result }
52
52
  }
53
53
 
54
+ {
55
+ //[0x68656C6C, 0x6F20776F, 0x726C6488] represents phrase 'hello world' with 1's at the end
56
+ const hash = _.computeSha256([0x68656C6C, 0x6F20776F, 0x726C64FF])(88)
57
+ const result = stringify(hash.map(toHexString))
58
+ if (result !== '["b94d27b9","934d3e08","a52e52d7","da7dabfa","c484efe3","7a5380ee","9088f7ac","e2efcde9"]') { throw result }
59
+ }
60
+
54
61
  {
55
62
  const input = Array(8).fill(0x31313131)
56
63
  const result = _.computeSha256(input)(256)