functionalscript 0.0.298 → 0.0.299

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.298",
3
+ "version": "0.0.299",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -32,30 +32,29 @@ const padding = input => length =>
32
32
  //console.log(outputLength)
33
33
  let o = new Array(outputLength / 32)
34
34
  //console.log(o.length)
35
+ /** @type {(i: number) => number} */
36
+ const f = i =>
37
+ i < appendBlockIndex ?
38
+ input[i] :
39
+ i === appendBlockIndex ?
40
+ (appendBlockIndex >= input.length ? 0x80000000 : appendOne(input[appendBlockIndex])(length % 32)) :
41
+ i === o.length - 2 ? (length / 4294967296) | 0 :
42
+ i === o.length - 1 ? length % 4294967296 : 0
35
43
  for(let i = 0; i < o.length; i++)
36
44
  {
37
- if (i < appendBlockIndex)
38
- o[i] = input[i];
39
- else if (i == appendBlockIndex)
40
- o[i] = appendBlockIndex >= input.length ? 0x80000000 : appendOne(input[appendBlockIndex])(length % 32);
41
- else if (i == o.length - 2)
42
- o[i] = Math.floor(length / 4294967296)
43
- else if (i == o.length - 1)
44
- o[i] = length % 4294967296
45
- else
46
- o[i] = 0
45
+ o[i] = f(i)
47
46
  }
48
47
  return o;
49
48
  }
50
49
 
51
50
  /** @type {(x: number) => (y: number) => (z: number) => number} */
52
- const ch = x => y => z =>
51
+ const ch = x => y => z =>
53
52
  {
54
53
  return x & y ^ ~x & z
55
54
  }
56
55
 
57
56
  /** @type {(x: number) => (y: number) => (z: number) => number} */
58
- const maj = x => y => z =>
57
+ const maj = x => y => z =>
59
58
  {
60
59
  return x & y ^ x & z ^ y & z
61
60
  }
@@ -73,25 +72,25 @@ const shr = n => d =>
73
72
  }
74
73
 
75
74
  /** @type {(x: number) => number} */
76
- const bsig0 = x =>
75
+ const bsig0 = x =>
77
76
  {
78
77
  return rotr(x)(2) ^ rotr(x)(13) ^ rotr(x)(22)
79
78
  }
80
79
 
81
80
  /** @type {(x: number) => number} */
82
- const bsig1 = x =>
81
+ const bsig1 = x =>
83
82
  {
84
83
  return rotr(x)(6) ^ rotr(x)(11) ^ rotr(x)(25)
85
84
  }
86
85
 
87
86
  /** @type {(x: number) => number} */
88
- const ssig0 = x =>
87
+ const ssig0 = x =>
89
88
  {
90
89
  return rotr(x)(7) ^ rotr(x)(18) ^ shr(x)(3)
91
90
  }
92
91
 
93
92
  /** @type {(x: number) => number} */
94
- const ssig1 = x =>
93
+ const ssig1 = x =>
95
94
  {
96
95
  return rotr(x)(17) ^ rotr(x)(19) ^ shr(x)(10)
97
96
  }
@@ -141,14 +140,14 @@ const computeSha256 = input => length =>
141
140
  {
142
141
  w[t] = padded[t + i * 16]
143
142
  }
144
-
143
+
145
144
  for(let t = 16; t < 64; t++)
146
145
  {
147
146
  w[t] = mod2pow32(ssig1(w[t - 2]) + w[t - 7] + ssig0(w[t-15]) + w[t - 16])
148
147
  }
149
-
148
+
150
149
  //console.log(w.map(toHexString))
151
-
150
+
152
151
  let a = h0
153
152
  let b = h1
154
153
  let c = h2
@@ -157,7 +156,7 @@ const computeSha256 = input => length =>
157
156
  let f = h5
158
157
  let g = h6
159
158
  let h = h7
160
-
159
+
161
160
  for(let t = 0; t < 64; t++)
162
161
  {
163
162
  let t1 = mod2pow32(h + bsig1(e) + ch(e)(f)(g) + k[t] + w[t])
@@ -171,7 +170,7 @@ const computeSha256 = input => length =>
171
170
  b = a
172
171
  a = mod2pow32(t1 + t2)
173
172
  }
174
-
173
+
175
174
  h0 = mod2pow32(h0 + a)
176
175
  h1 = mod2pow32(h1 + b)
177
176
  h2 = mod2pow32(h2+ c)