functionalscript 0.7.0 → 0.8.1

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.
Files changed (125) hide show
  1. package/LICENSE +21 -661
  2. package/README.md +3 -2
  3. package/bnf/data/module.f.d.ts +16 -6
  4. package/bnf/data/module.f.js +115 -23
  5. package/bnf/data/test.f.d.ts +4 -0
  6. package/bnf/data/test.f.js +389 -14
  7. package/bnf/module.f.d.ts +5 -4
  8. package/bnf/module.f.js +1 -1
  9. package/bnf/testlib.f.js +1 -1
  10. package/ci/module.f.d.ts +3 -0
  11. package/ci/module.f.js +169 -0
  12. package/ci/module.js +3 -0
  13. package/crypto/hmac/module.f.d.ts +5 -4
  14. package/crypto/hmac/module.f.js +9 -18
  15. package/crypto/hmac/test.f.d.ts +1 -0
  16. package/crypto/hmac/test.f.js +16 -8
  17. package/crypto/prime_field/module.f.d.ts +1 -1
  18. package/crypto/prime_field/module.f.js +4 -3
  19. package/crypto/prime_field/test.f.js +13 -13
  20. package/crypto/rfc6979/module.f.d.ts +15 -0
  21. package/crypto/rfc6979/module.f.js +98 -0
  22. package/crypto/rfc6979/test.f.d.ts +10 -0
  23. package/crypto/rfc6979/test.f.js +490 -0
  24. package/crypto/secp/module.f.d.ts +4 -4
  25. package/crypto/secp/module.f.js +1 -1
  26. package/crypto/secp/test.f.js +8 -8
  27. package/crypto/sha2/module.f.d.ts +11 -5
  28. package/crypto/sha2/module.f.js +4 -3
  29. package/crypto/sha2/test.f.d.ts +4 -1
  30. package/crypto/sha2/test.f.js +41 -31
  31. package/crypto/sign/module.f.d.ts +1 -1
  32. package/crypto/sign/module.f.js +3 -2
  33. package/dev/tf/all.test.js +9 -1
  34. package/djs/ast/module.f.d.ts +3 -3
  35. package/djs/ast/test.f.js +7 -8
  36. package/djs/parser/module.f.d.ts +3 -3
  37. package/djs/parser/module.f.js +4 -4
  38. package/djs/parser/test.f.js +76 -77
  39. package/djs/serializer/module.f.d.ts +8 -8
  40. package/djs/serializer/module.f.js +4 -7
  41. package/djs/serializer/test.f.js +8 -9
  42. package/djs/tokenizer/module.f.d.ts +2 -2
  43. package/djs/tokenizer/module.f.js +3 -5
  44. package/djs/tokenizer/test.f.js +8 -10
  45. package/djs/transpiler/module.f.d.ts +3 -3
  46. package/djs/transpiler/module.f.js +2 -0
  47. package/fsc/bnf.f.d.ts +1 -1
  48. package/fsc/bnf.f.js +39 -51
  49. package/fsc/json.f.d.ts +1 -1
  50. package/fsc/json.f.js +56 -81
  51. package/fsc/test.f.d.ts +5 -0
  52. package/fsc/test.f.js +69 -7
  53. package/fsm/module.f.js +3 -3
  54. package/fsm/test.f.js +21 -25
  55. package/html/module.f.js +17 -4
  56. package/html/test.f.d.ts +7 -0
  57. package/html/test.f.js +37 -0
  58. package/issues/031-json.f.d.ts +1 -0
  59. package/js/tokenizer/module.f.d.ts +4 -4
  60. package/js/tokenizer/module.f.js +12 -17
  61. package/js/tokenizer/test.f.js +9 -11
  62. package/json/module.f.d.ts +6 -6
  63. package/json/module.f.js +5 -10
  64. package/json/parser/module.f.d.ts +4 -4
  65. package/json/parser/module.f.js +7 -4
  66. package/json/parser/test.f.js +47 -49
  67. package/json/serializer/module.f.d.ts +6 -6
  68. package/json/serializer/module.f.js +3 -2
  69. package/json/serializer/test.f.js +13 -13
  70. package/json/test.f.js +13 -15
  71. package/json/tokenizer/module.f.d.ts +4 -4
  72. package/json/tokenizer/module.f.js +6 -7
  73. package/json/tokenizer/test.f.js +7 -9
  74. package/nanvm-lib/tests/vm/test.f.d.ts +25 -0
  75. package/nanvm-lib/tests/vm/test.f.js +105 -0
  76. package/package.json +8 -8
  77. package/text/ascii/test.f.js +2 -2
  78. package/text/module.f.d.ts +3 -2
  79. package/text/module.f.js +2 -2
  80. package/text/test.f.js +3 -3
  81. package/text/utf16/test.f.js +2 -2
  82. package/text/utf8/test.f.js +2 -2
  83. package/types/array/test.f.js +2 -2
  84. package/types/bigint/module.f.d.ts +6 -3
  85. package/types/bigint/module.f.js +12 -11
  86. package/types/bigint/test.f.d.ts +2 -0
  87. package/types/bigint/test.f.js +21 -2
  88. package/types/bit_vec/module.f.d.ts +66 -34
  89. package/types/bit_vec/module.f.js +97 -32
  90. package/types/bit_vec/test.f.d.ts +7 -0
  91. package/types/bit_vec/test.f.js +283 -62
  92. package/types/btree/find/test.f.js +9 -8
  93. package/types/btree/remove/test.f.js +4 -4
  94. package/types/btree/set/test.f.js +4 -4
  95. package/types/btree/test.f.js +7 -7
  96. package/types/byte_set/test.f.js +2 -2
  97. package/types/function/compare/module.f.d.ts +15 -1
  98. package/types/function/compare/module.f.js +1 -1
  99. package/types/function/compare/test.f.js +37 -4
  100. package/types/list/test.f.js +93 -93
  101. package/types/monoid/module.f.d.ts +4 -4
  102. package/types/monoid/module.f.js +3 -3
  103. package/types/monoid/test.f.js +3 -3
  104. package/types/nominal/module.f.d.ts +5 -0
  105. package/types/nominal/module.f.js +4 -0
  106. package/types/nominal/test.f.d.ts +5 -0
  107. package/types/nominal/test.f.js +53 -0
  108. package/types/number/module.f.js +2 -2
  109. package/types/range_map/test.f.js +21 -21
  110. package/types/sorted_list/test.f.js +10 -10
  111. package/types/sorted_set/test.f.js +14 -14
  112. package/types/string/module.f.js +2 -2
  113. package/types/string_set/module.f.js +3 -3
  114. package/bnf/djs/module.f.d.ts +0 -77
  115. package/bnf/djs/module.f.js +0 -207
  116. package/bnf/djs/test.f.d.ts +0 -8
  117. package/bnf/djs/test.f.js +0 -277
  118. package/bnf/func/module.f.d.ts +0 -148
  119. package/bnf/func/module.f.js +0 -132
  120. package/bnf/func/test.f.d.ts +0 -12
  121. package/bnf/func/test.f.js +0 -171
  122. package/bnf/func/testlib.f.d.ts +0 -25
  123. package/bnf/func/testlib.f.js +0 -150
  124. /package/{issues/31-json.f.d.ts → ci/module.d.ts} +0 -0
  125. /package/issues/{31-json.f.js → 031-json.f.js} +0 -0
@@ -0,0 +1,490 @@
1
+ import { utf8 } from "../../text/module.f.js";
2
+ import { empty, msb, repeat, vec, vec8 } from "../../types/bit_vec/module.f.js";
3
+ import { hmac } from "../hmac/module.f.js";
4
+ import { computeSync, sha224, sha256, sha384, sha512 } from "../sha2/module.f.js";
5
+ import { all, concat, computeK } from "./module.f.js";
6
+ const sample = utf8("sample");
7
+ const test = utf8("test");
8
+ const x00 = vec8(0x00n);
9
+ const x01 = vec8(0x01n);
10
+ const v168 = vec(168n);
11
+ const v256 = vec(256n);
12
+ const v600 = vec(600n);
13
+ const r32 = repeat(32n);
14
+ const hmac256 = hmac(sha256);
15
+ export default {
16
+ bits2int: () => {
17
+ if (all(7n).bits2int(vec(5n)(20n)) !== 5n) {
18
+ throw new Error("fail");
19
+ }
20
+ if (all(17n).bits2int(vec(3n)(5n)) !== 5n) {
21
+ throw new Error("fail");
22
+ }
23
+ },
24
+ int2octets: () => {
25
+ // 3 bit prime
26
+ if (all(5n).int2octets(5n) !== vec(8n)(5n)) {
27
+ throw new Error("fail");
28
+ }
29
+ // 5 bit prime
30
+ if (all(17n).int2octets(20n) !== vec(8n)(20n)) {
31
+ throw new Error("fail");
32
+ }
33
+ // 15 bit prime
34
+ if (all(16387n).int2octets(0x13n) !== vec(16n)(0x13n)) {
35
+ throw new Error("fail");
36
+ }
37
+ },
38
+ bit2octets: () => {
39
+ if (all(11n).bits2octets(vec(4n)(13n)) !== vec(8n)(2n)) {
40
+ throw new Error("fail");
41
+ }
42
+ },
43
+ k: () => {
44
+ //
45
+ const q = 0x4000000000000000000020108a2e0cc0d99f8a5efn;
46
+ const { qlen, int2octets, bits2octets, bits2int } = all(q);
47
+ if (qlen !== 163n) {
48
+ throw qlen;
49
+ }
50
+ const x = 0x09a4d6792295a7f730fc3f2b49cbc0f62e862272fn;
51
+ const h1 = computeSync(sha256)([sample]);
52
+ if (h1 !== v256(0xaf2bdbe1aa9b6ec1e2ade1d694f41fc71a831d0268e9891562113d8a62add1bfn)) {
53
+ throw h1;
54
+ }
55
+ const xi2o = int2octets(x);
56
+ if (xi2o !== v168(0x009a4d6792295a7f730fc3f2b49cbc0f62e862272fn)) {
57
+ throw xi2o;
58
+ }
59
+ const h1b2o = bits2octets(h1);
60
+ if (h1b2o !== v168(0x01795edf0d54db760f156d0dac04c0322b3a204224n)) {
61
+ throw h1b2o;
62
+ }
63
+ let v = r32(x01);
64
+ if (v !== v256(0x0101010101010101010101010101010101010101010101010101010101010101n)) {
65
+ throw v;
66
+ }
67
+ let k = r32(x00);
68
+ if (k !== v256(0x0000000000000000000000000000000000000000000000000000000000000000n)) {
69
+ throw k;
70
+ }
71
+ // d.
72
+ // 256 + 8 + 168 + 168 = 600
73
+ const vv = concat(v, x00, xi2o, h1b2o);
74
+ const vvu = 0x010101010101010101010101010101010101010101010101010101010101010100009a4d6792295a7f730fc3f2b49cbc0f62e862272f01795edf0d54db760f156d0dac04c0322b3a204224n;
75
+ if (vv !== v600(vvu)) {
76
+ throw [vv.toString(16), vvu.toString(16)];
77
+ }
78
+ k = hmac256(k)(vv);
79
+ if (k !== v256(0x09999a9bfef972d3346911883fad7951d23f2c8b47f420222d1171eeeeac5ab8n)) {
80
+ throw k;
81
+ }
82
+ // e.
83
+ v = hmac256(k)(v);
84
+ if (v !== v256(0xd5f4030f755ee86aa10bba8c09df114ff6b6111c238500d13c7343a8c01becf7n)) {
85
+ throw v;
86
+ }
87
+ // f. K = HMAC_K(V || 0x01 || int2octets(x) || bits2octets(h1))
88
+ k = hmac256(k)(concat(v, x01, xi2o, h1b2o));
89
+ if (k !== v256(0x0cf2fe96d5619c9ef53cb7417d49d37ea68a4ffed0d7e623e38689289911bd57n)) {
90
+ throw k;
91
+ }
92
+ // g.
93
+ v = hmac256(k)(v);
94
+ if (v !== v256(0x783457c1cf3148a8f2a9ae73ed472fa98ed9cd925d8e964ce0764def3f842b9an)) {
95
+ throw v;
96
+ }
97
+ // h.
98
+ v = hmac256(k)(v);
99
+ let t = msb.concat(empty)(v);
100
+ if (t !== v256(0x9305a46de7ff8eb107194debd3fd48aa20d5e7656cbe0ea69d2a8d4e7c67314an)) {
101
+ throw t;
102
+ }
103
+ // 3.
104
+ let kk = bits2int(t);
105
+ if (kk !== 0x4982d236f3ffc758838ca6f5e9fea455106af3b2bn) {
106
+ throw kk;
107
+ }
108
+ // 3. second try
109
+ k = hmac256(k)(concat(v, x00));
110
+ if (k !== v256(0x75cb5c05b2a78c3d81df12d74d7be0a0e94ab19815781d4d8e2902a79d0a6699n)) {
111
+ throw k;
112
+ }
113
+ v = hmac256(k)(v);
114
+ if (v !== v256(0xdcb9ca126107a9c27ce77ba58ea871c8c912d835eaddc305f2445d88f66c4c43n)) {
115
+ throw v;
116
+ }
117
+ v = hmac256(k)(v);
118
+ t = msb.concat(empty)(v);
119
+ if (t !== v256(0xc70c78608a3b5be9289be90ef6e81a9e2c1516d5751d2f75f50033e45f73bdebn)) {
120
+ throw t;
121
+ }
122
+ kk = bits2int(t);
123
+ if (kk !== 0x63863c30451dadf4944df4877b740d4f160a8b6abn) {
124
+ throw kk;
125
+ }
126
+ // 3. third try
127
+ k = hmac256(k)(concat(v, x00));
128
+ if (k !== v256(0x0a5a64b99c059520103686cb6f36bcfca788eb3bcf69ba66a5bb080b0593ba53n)) {
129
+ throw k;
130
+ }
131
+ v = hmac256(k)(v);
132
+ if (v !== v256(0x0b3b196811b19f6c6f729c43f35bcf0dfd725f17ca3430e8721453e55550a18fn)) {
133
+ throw v;
134
+ }
135
+ v = hmac256(k)(v);
136
+ t = msb.concat(empty)(v);
137
+ if (t !== v256(0x475e80e992140567fcc3a50dab90fe84bcd7bb03638e9c4656a06f37f6508a7cn)) {
138
+ throw t;
139
+ }
140
+ kk = bits2int(t);
141
+ if (kk !== 0x23af4074c90a02b3fe61d286d5c87f425e6bdd81bn) {
142
+ throw kk;
143
+ }
144
+ },
145
+ computeK: () => {
146
+ const q = 0x4000000000000000000020108a2e0cc0d99f8a5efn;
147
+ const a = all(q);
148
+ if (a.qlen !== 163n) {
149
+ throw a.qlen;
150
+ }
151
+ const x = 0x09a4d6792295a7f730fc3f2b49cbc0f62e862272fn;
152
+ const k = computeK(a)(sha256)(x)(sample);
153
+ if (k !== 0x23af4074c90a02b3fe61d286d5c87f425e6bdd81bn) {
154
+ throw k;
155
+ }
156
+ },
157
+ investigate: () => {
158
+ const q = 0xf2c3119374ce76c9356990b465374a17f23f9ed35089bd969f61c6dde9998c1fn;
159
+ const x = 0x69c7548c21d0dfea6b9a51c9ead4e27c33d3b3f180316e5bcab92c933f0e4dbcn;
160
+ const a = all(q);
161
+ // h = 9A9083505BC92276AEC4BE312696EF7BF3BF603F4BBD381196A029F340585312313BCA4A9B5B890EFEE42C77B1EE25FE
162
+ // 9a9083505bc92276aec4be312696ef7bf3bf603f4bbd381196a029f340585312313bca4a9b5b890efee42c77b1ee25fe
163
+ // d.
164
+ // 010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101
165
+ // 010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101
166
+ // 69c7548c21d0dfea6b9a51c9ead4e27c33d3b3f180316e5bcab92c933f0e4dbc9a9083505bc92276aec4be312696ef7bf3bf603f4bbd381196a029f340585312
167
+ // 69C7548C21D0DFEA6B9A51C9EAD4E27C33D3B3F180316E5BCAB92C933F0E4DBC9A9083505BC92276AEC4BE312696EF7BF3BF603F4BBD381196A029F340585312
168
+ // k = 9fd1afe82743d433f901f78b91de8aa2fd12a27ef55c2dccb805add1f58374a04cea7a85a04e7b29a948afa376e45371
169
+ // 8F858157CE005CD52FD8E8F1A46B55E6CFAE21C8C183D9C2F7504BEDF450609EDD7D3C6171DC0BDD2D2444FAA28F18BA
170
+ // e.
171
+ // v = db52abd3854c335f5cac1087bb5cedf862426614048a9b4a63432aa53959f0ad121d361e65de4f1d9bc0e6985f705760
172
+ // f.
173
+ // k = d3a964b8401e7c4f95d59451f7d9d13089088e75d911f45da75a19094256fa698fb88f230dae9b091d2582a3bd60661c
174
+ // g.
175
+ // v = 978d2cd1b2bc80d44ec98e32f0bf8bd0d5aa62bf32549eeed05ebe28dc1543d7f08b93b4984f76ca4f9542b45ef526bd
176
+ // h.
177
+ // v = 14b76af28ee2a86fa9ebbd6b6f2f2899cea140658741d21d679dbbdced2fc81b25db22c479e55be8f6f556d181ebeacf
178
+ // result = 14b76af28ee2a86fa9ebbd6b6f2f2899cea140658741d21d679dbbdced2fc81b
179
+ const k = computeK(a)(sha384)(x)(sample);
180
+ // // our implementation
181
+ // if (k !== 0x14b76af28ee2a86fa9ebbd6b6f2f2899cea140658741d21d679dbbdced2fc81bn) { throw k }
182
+ // // reference
183
+ // if (k !== 0xC345D5AB3DA0A5BCB7EC8F8FB7A7E96069E03B206371EF7D83E39068EC564920n) { throw k }
184
+ },
185
+ a2: () => {
186
+ const check = ({ q, x, s, t }) => {
187
+ const a = all(q);
188
+ const check = (s, expected, m) => {
189
+ const k = computeK(a)(s)(x)(m);
190
+ if (k !== expected) {
191
+ throw [k.toString(16), expected.toString(16)];
192
+ }
193
+ };
194
+ const check4 = (m, h) => {
195
+ check(sha224, h[0], m);
196
+ check(sha256, h[1], m);
197
+ check(sha384, h[2], m);
198
+ check(sha512, h[3], m);
199
+ };
200
+ check4(sample, s);
201
+ check4(test, t);
202
+ };
203
+ const testVectors = {
204
+ x1: {
205
+ q: 0x996f967f6c8e388d9e28d01e205fba957a5698b1n,
206
+ x: 0x411602cb19a6ccc34494d79d98ef1e7ed5af25f7n,
207
+ s: [
208
+ 0x562097c06782d60c3037ba7be104774344687649n,
209
+ 0x519ba0546d0c39202a7d34d7dfa5e760b318bcfbn,
210
+ 0x95897cd7bbb944aa932dbc579c1c09eb6fcfc595n,
211
+ 0x09ece7ca27d0f5a4dd4e556c9df1d21d28104f8bn
212
+ ],
213
+ t: [
214
+ 0x4598b8efc1a53bc8aecd58d1abbb0c0c71e67297n,
215
+ 0x5a67592e8128e03a417b0484410fb72c0b630e1an,
216
+ 0x220156b761f6ca5e6c9f1b9cf9c24be25f98cd89n,
217
+ 0x65d2c2eeb175e370f28c75bfcdc028d22c7dbe9cn
218
+ ]
219
+ },
220
+ x2: {
221
+ q: 0xf2c3119374ce76c9356990b465374a17f23f9ed35089bd969f61c6dde9998c1fn,
222
+ x: 0x69c7548c21d0dfea6b9a51c9ead4e27c33d3b3f180316e5bcab92c933f0e4dbcn,
223
+ s: [
224
+ 0xbc372967702082e1aa4fce892209f71ae4ad25a6dfd869334e6f153bd0c4d806n,
225
+ 0x8926a27c40484216f052f4427cfd5647338b7b3939bc6573af4333569d597c52n,
226
+ 0xc345d5ab3da0a5bcb7ec8f8fb7a7e96069e03b206371ef7d83e39068ec564920n,
227
+ 0x5a12994431785485b3f5f067221517791b85a597b7a9436995c89ed0374668fcn,
228
+ ],
229
+ t: [
230
+ 0x06bd4c05ed74719106223be33f2d95da6b3b541dad7bfbd7ac508213b6da6670n,
231
+ 0x1d6ce6dda1c5d37307839cd03ab0a5cbb18e60d800937d67dfb4479aac8dead7n,
232
+ 0x206e61f73dbe1b2dc8be736b22b079e9dacd974db00eebbc5b64cad39cf9f91cn,
233
+ 0xaff1651e4cd6036d57aa8b2a05ccf1a9d5a40166340ecbbdc55be10b568aa0aan,
234
+ ],
235
+ },
236
+ x3: {
237
+ q: 0xffffffffffffffffffffffff99def836146bc9b1b4d22831n,
238
+ x: 0x6fab034934e4c0fc9ae67f5b5659a9d7d1fefd187ee09fd4n,
239
+ s: [
240
+ 0x4381526b3fc1e7128f202e194505592f01d5ff4c5af015d8n,
241
+ 0x32b1b6d7d42a05cb449065727a84804fb1a3e34d8f261496n,
242
+ 0x4730005c4fcb01834c063a7b6760096dbe284b8252ef4311n,
243
+ 0xa2ac7ab055e4f20692d49209544c203a7d1f2c0bfbc75db1n
244
+ ],
245
+ t: [
246
+ 0xf5dc805f76ef851800700cce82e7b98d8911b7d510059fben,
247
+ 0x5c4ce89cf56d9e7c77c8585339b006b97b5f0680b4306c6cn,
248
+ 0x5afefb5d3393261b828db6c91fbc68c230727b030c975693n,
249
+ 0x0758753a5254759c7cfbad2e2d9b0792eee44136c9480527n,
250
+ ],
251
+ },
252
+ x4: {
253
+ q: 0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3dn,
254
+ x: 0xf220266e1105bfe3083e03ec7a3a654651f45e37167e88600bf257c1n,
255
+ s: [
256
+ 0xc1d1f2f10881088301880506805feb4825fe09acb6816c36991aa06dn,
257
+ 0xad3029e0278f80643de33917ce6908c70a8ff50a411f06e41dedfcdcn,
258
+ 0x52b40f5a9d3d13040f494e83d3906c6079f29981035c7bd51e5cac40n,
259
+ 0x9db103ffededf9cfdba05184f925400c1653b8501bab89cea0fbec14n,
260
+ ],
261
+ t: [
262
+ 0xdf8b38d40dca3e077d0ac520bf56b6d565134d9b5f2eae0d34900524n,
263
+ 0xff86f57924da248d6e44e8154eb69f0ae2aebaee9931d0b5a969f904n,
264
+ 0x7046742b839478c1b5bd31db2e862ad868e1a45c863585b5f22bdc2dn,
265
+ 0xe39c2aa4ea6be2306c72126d40ed77bf9739bb4d6ef2bbb1dcb6169dn,
266
+ ],
267
+ },
268
+ x5: {
269
+ q: 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551n,
270
+ x: 0xc9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721n,
271
+ s: [
272
+ 0x103f90ee9dc52e5e7fb5132b7033c63066d194321491862059967c715985d473n,
273
+ 0xa6e3c57dd01abe90086538398355dd4c3b17aa873382b0f24d6129493d8aad60n,
274
+ 0x09f634b188cefd98e7ec88b1aa9852d734d0bc272f7d2a47decc6ebeb375aad4n,
275
+ 0x5fa81c63109badb88c1f367b47da606da28cad69aa22c4fe6ad7df73a7173aa5n,
276
+ ],
277
+ t: [
278
+ 0x669f4426f2688b8be0db3a6bd1989bdaefff84b649eeb84f3dd26080f667faa7n,
279
+ 0xd16b6ae827f17175e040871a1c7ec3500192c4c92677336ec2537acaee0008e0n,
280
+ 0x16aeffa357260b04b1dd199693960740066c1a8f3e8edd79070aa914d361b3b8n,
281
+ 0x6915d11632aca3c40d5d51c08daf9c555933819548784480e93499000d9f0b7fn,
282
+ ],
283
+ },
284
+ x6: {
285
+ q: 0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973n,
286
+ x: 0x6b9d3dad2e1b8c1c05b19875b6659f4de23c3b667bf297ba9aa47740787137d896d5724e4c70a825f872c9ea60d2edf5n,
287
+ s: [
288
+ 0xa4e4d2f0e729eb786b31fc20ad5d849e304450e0ae8e3e341134a5c1afa03cab8083ee4e3c45b06a5899ea56c51b5879n,
289
+ 0x180ae9f9aec5438a44bc159a1fcb277c7be54fa20e7cf404b490650a8acc414e375572342863c899f9f2edf9747a9b60n,
290
+ 0x94ed910d1a099dad3254e9242ae85abde4ba15168eaf0ca87a555fd56d10fbca2907e3e83ba95368623b8c4686915cf9n,
291
+ 0x92fc3c7183a883e24216d1141f1a8976c5b0dd797dfa597e3d7b32198bd35331a4e966532593a52980d0e3aaa5e10ec3n,
292
+ ],
293
+ t: [
294
+ 0x18fa39db95aa5f561f30fa3591dc59c0fa3653a80daffa0b48d1a4c6dfcbff6e3d33be4dc5eb8886a8ecd093f2935726n,
295
+ 0x0cfac37587532347dc3389fdc98286bba8c73807285b184c83e62e26c401c0faa48dd070ba79921a3457abff2d630ad7n,
296
+ 0x015ee46a5bf88773ed9123a5ab0807962d193719503c527b031b4c2d225092ada71f4a459bc0da98adb95837db8312ean,
297
+ 0x3780c4f67cb15518b6acae34c9f83568d2e12e47deab6c50a4e4ee5319d1e8ce0e2cc8a136036dc4b9c00e6888f66b6cn,
298
+ ],
299
+ },
300
+ x7: {
301
+ q: 0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409n,
302
+ x: 0x0fad06daa62ba3b25d2fb40133da757205de67f5bb0018fee8c86e1b68c7e75caa896eb32f1f47c70855836a6d16fcc1466f6d8fbec67db89ec0c08b0e996b83538n,
303
+ s: [
304
+ 0x121415ec2cd7726330a61f7f3fa5de14be9436019c4db8cb4041f3b54cf31be0493ee3f427fb906393d895a19c9523f3a1d54bb8702bd4aa9c99dab2597b92113f3n,
305
+ 0x0edf38afcaaecab4383358b34d67c9f2216c8382aaea44a3dad5fdc9c32575761793fef24eb0fc276dfc4f6e3ec476752f043cf01415387470bcbd8678ed2c7e1a0n,
306
+ 0x1546a108bc23a15d6f21872f7ded661fa8431ddbd922d0dcdb77cc878c8553ffad064c95a920a750ac9137e527390d2d92f153e66196966ea554d9adfcb109c4211n,
307
+ 0x1dae2ea071f8110dc26882d4d5eae0621a3256fc8847fb9022e2b7d28e6f10198b1574fdd03a9053c08a1854a168aa5a57470ec97dd5ce090124ef52a2f7ecbffd3n,
308
+ ],
309
+ t: [
310
+ 0x040d09fcf3c8a5f62cf4fb223cbbb2b9937f6b0577c27020a99602c25a01136987e452988781484edbbcf1c47e554e7fc901bc3085e5206d9f619cff07e73d6f706n,
311
+ 0x01de74955efaabc4c4f17f8e84d881d1310b5392d7700275f82f145c61e843841af09035bf7a6210f5a431a6a9e81c9323354a9e69135d44ebd2fcaa7731b909258n,
312
+ 0x1f1fc4a349a7da9a9e116bfdd055dc08e78252ff8e23ac276ac88b1770ae0b5dceb1ed14a4916b769a523ce1e90ba22846af11df8b300c38818f713dadd85de0c88n,
313
+ 0x16200813020ec986863bedfc1b121f605c1215645018aea1a7b215a564de9eb1b38a67aa1128b80ce391c4fb71187654aaa3431027bfc7f395766ca988c964dc56dn,
314
+ ]
315
+ },
316
+ x8: {
317
+ q: 0x4000000000000000000020108a2e0cc0d99f8a5efn,
318
+ x: 0x09a4d6792295a7f730fc3f2b49cbc0f62e862272fn,
319
+ s: [
320
+ 0x323e7b28bfd64e6082f5b12110aa87bc0d6a6e159n,
321
+ 0x23af4074c90a02b3fe61d286d5c87f425e6bdd81bn,
322
+ 0x2132abe0ed518487d3e4fa7fd24f8bed1f29ccfcen,
323
+ 0x00bbcc2f39939388fdfe841892537ec7b1ff33aa3n,
324
+ ],
325
+ t: [
326
+ 0x091dd986f38eb936be053dd6ace3419d2642ade8dn,
327
+ 0x193649ce51f0cff0784cfc47628f4fa854a93f7a2n,
328
+ 0x37c73c6f8b404ec83da17a6ebca724b3ff1f7eeban,
329
+ 0x331ad98d3186f73967b1e0b120c80b1e22efc2988n,
330
+ ],
331
+ },
332
+ x9: {
333
+ q: 0x8000000000000000000000000000069d5bb915bcd46efb1ad5f173abdfn,
334
+ x: 0x103b2142bdc2a3c3b55080d09df1808f79336da2399f5ca7171d1be9b0n,
335
+ s: [
336
+ 0x71626a309d9cd80ad0b975d757fe6bf4b84e49f8f34c780070d7746f19n,
337
+ 0x73552f9cac5774f74f485fa253871f2109a0c86040552eaa67dba92dc9n,
338
+ 0x17d726a67539c609bd99e29aa3737ef247724b71455c3b6310034038c8n,
339
+ 0x0e535c328774cde546be3af5d7fcd263872f107e807435105ba2fdc166n,
340
+ ],
341
+ t: [
342
+ 0x67634d0aba2c9bf7ae54846f26dcd166e7100654bce6fdc96667631aa2n,
343
+ 0x2ce5aedc155acc0ddc5e679ebacfd21308362e5efc05c5e99b2557a8d7n,
344
+ 0x1b4bd3903e74fd0b31e23f956c70062014dfefee21832032ea5352a055n,
345
+ 0x1775ed919ca491b5b014c5d5e86af53578b5a7976378f192af665cb705n,
346
+ ],
347
+ },
348
+ x10: {
349
+ q: 0x1ffffffffffffffffffffffffffffffffffe9ae2ed07577265dff7f94451e061e163c61n,
350
+ x: 0x06a0777356e87b89ba1ed3a3d845357be332173c8f7a65bdc7db4fab3c4cc79acc8194en,
351
+ s: [
352
+ 0x1b4c4e3b2f6b08b5991bd2bdde277a7016da527ad0aae5bc61b64c5a0ee63e8b502ef61n,
353
+ 0x1ceb9e8e0dff53ce687deb81339aca3c98e7a657d5a9499ef779f887a934408ecbe5a38n,
354
+ 0x1460a5c41745a5763a9d548ae62f2c3630bbed71b6aa549d7f829c22442a728c5d965dan,
355
+ 0x00f3b59fcb5c1a01a1a2a0019e98c244dff61502d6e6b9c4e957eddceb258ef4dbef04an,
356
+ ],
357
+ t: [
358
+ 0x045e13ea645ce01d9b25ea38c8a8a170e04c83bb7f231ee3152209fe10ec8b2e565536cn,
359
+ 0x0b585a7a68f51089691d6ede2b43fc4451f66c10e65f134b963d4cbd4eb844b0e1469a6n,
360
+ 0x1e88738e14482a09ee16a73d490a7fe8739df500039538d5c4b6c8d6d7f208d6ca56760n,
361
+ 0x00e5f24a223bd459653f682763c3bb322d4ee75dd89c63d4dc61518d543e76585076bban,
362
+ ],
363
+ },
364
+ x11: {
365
+ q: 0x7ffffffffffffffffffffffffffffffffffffffffffffffffffe5f83b2d4ea20400ec4557d5ed3e3e7ca5b4b5c83b8e01e5fcfn,
366
+ x: 0x29c16768f01d1b8a89fda85e2efd73a09558b92a178a2931f359e4d70ad853e569cdaf16daa569758fb4e73089e4525d8bbfcfn,
367
+ s: [
368
+ 0x512340db682c7b8ebe407bf1aa54194dfe85d49025fe0f632c9b8a06a996f2fcd0d73c752fb09d23db8fbe50605dc25df0745cn,
369
+ 0x782385f18baf5a36a588637a76dfab05739a14163bf723a4417b74bd1469d37ac9e8cce6aec8ff63f37b815aaf14a876eed962n,
370
+ 0x4da637cb2e5c90e486744e45a73935dd698d4597e736da332a06eda8b26d5abc6153ec2ece14981cf3e5e023f36ffa55eea6d7n,
371
+ 0x57055b293ecfdfe983cef716166091e573275c53906a39eadc25c89c5ec8d7a7e5629fcfdfad514e1348161c9a34ea1c42d58cn,
372
+ ],
373
+ t: [
374
+ 0x3c5352929d4ebe3cce87a2dce380f0d2b33c901e61abc530daf3506544ab0930ab9bfd553e51fcda44f06cd2f49e17e07db519n,
375
+ 0x251e32dee10ed5ea4ad7370df3eff091e467d5531ca59de3aa791763715e1169ab5e18c2a11cd473b0044fb45308e8542f2eb0n,
376
+ 0x11c540ea46c5038fe28bb66e2e9e9a04c9fe9567adf33d56745953d44c1dc8b5b92922f53a174e431c0ed8267d919329f19014n,
377
+ 0x59527ce953bc09df5e85155cae7bb1d7f342265f41635545b06044f844ecb4fa6476e7d47420adc8041e75460ec0a4ec760e95n,
378
+ ],
379
+ },
380
+ x12: {
381
+ q: 0x20000000000000000000000000000000000000000000000000000000000000000000000131850e1f19a63e4b391a8db917f4138b630d84be5d639381e91deb45cfe778f637c1001n,
382
+ x: 0x0c16f58550d824ed7b95569d4445375d3a490bc7e0194c41a39deb732c29396cdf1d66de02dd1460a816606f3bec0f32202c7bd18a32d87506466aa92032f1314ed7b19762b0d22n,
383
+ s: [
384
+ 0x0b599d068a1a00498ee0b9ad6f388521f594bd3f234e47f7a1db6490d7b57d60b0101b36f39cc22885f78641c69411279706f0989e6991e5d5b53619e43efb397e25e0814ef02bcn,
385
+ 0x0f79d53e63d89fb87f4d9e6dc5949f5d9388bcfe9ebcb4c2f7ce497814cf40e845705f8f18dbf0f860de0b1cc4a433ef74a5741f3202e958c082e0b76e16ecd5866aa0f5f3df300n,
386
+ 0x0308253c022d25f8a9ebcd24459dd6596590bdec7895618eee8a2623a98d2a2b2e7594ee6b7ad3a39d70d68cb4ed01cb28e2129f8e2cc0cc8dc7780657e28bcd655f0be9b7d35a2n,
387
+ 0x0c5ee7070af55f84ebc43a0d481458cede1dcebb57720a3c92f59b4941a044fecff4f703940f3121773595e880333772acf822f2449e17c64da286bcd65711dd5da44d7155bf004n,
388
+ ],
389
+ t: [
390
+ 0x1da875065b9d94dbe75c61848d69578bcc267935792624f9887b53c9af9e43cabfc42e4c3f9a456ba89e717d24f1412f33cfd297a7a4d403b18b5438654c74d592d5022125e0c6bn,
391
+ 0x04ddd0707e81bb56ea2d1d45d7fafdbdd56912cae224086802fea1018db306c4fb8d93338dbf6841ce6c6ab1506e9a848d2c0463e0889268843dee4acb552cffcb858784ed116b2n,
392
+ 0x0141b53dc6e569d8c0c0718a58a5714204502fda146e7e2133e56d19e905b79413457437095de13cf68b5cf5c54a1f2e198a55d974fc3e507afc0acf95ed391c93cc79e3b3fe37cn,
393
+ 0x14842f97f263587a164b215dd0f912c588a88dc4ab6af4c530adc1226f16e086d62c14435e6bfab56f019886c88922d2321914ee41a8f746aaa2b964822e4ac6f40ee2492b66824n,
394
+ ],
395
+ },
396
+ x13: {
397
+ q: 0x40000000000000000000292fe77e70c12a4234c33n,
398
+ x: 0x35318fc447d48d7e6bc93b48617dddedf26aa658fn,
399
+ s: [
400
+ 0x3b24c5e2c2d935314eabf57a6484289b291adfe3fn,
401
+ 0x3d7086a59e6981064a9cdb684653f3a81b6ec0f0bn,
402
+ 0x3b1e4443443486c7251a68ef184a936f05f8b17c7n,
403
+ 0x2edf5cfcac7553c17421fdf54ad1d2ef928a879d2n,
404
+ ],
405
+ t: [
406
+ 0x34f46de59606d56c75406bfb459537a7cc280aa62n,
407
+ 0x38145e3ffca94e4ddacc20ad6e0997bd0e3b669d2n,
408
+ 0x375813210ece9c4d7ab42ddc3c55f89189cf6dffdn,
409
+ 0x25ad8b393bc1e9363600fda1a2ab6df40079179a3n,
410
+ ]
411
+ },
412
+ x14: {
413
+ q: 0x1000000000000000000000000000013e974e72f8a6922031d2603cfe0d7n,
414
+ x: 0x07adc13dd5bf34d1ddeeb50b2ce23b5f5e6d18067306d60c5f6ff11e5d3n,
415
+ s: [
416
+ 0x0f2b1c1e80beb58283aaa79857f7b83bdf724120d0913606fd07f7ffb2cn,
417
+ 0x034a53897b0bbdb484302e19bf3f9b34a2abfed639d109a388dc52006b5n,
418
+ 0x04d4670b28990bc92eeb49840b482a1fa03fe028d09f3d21f89c67eca85n,
419
+ 0x0de108aaada760a14f42c057ef81c0a31af6b82e8fbca8dc86e443ab549n,
420
+ ],
421
+ t: [
422
+ 0x07bdb6a7fd080d9ec2fc84bff9e3e15750789dc04290c84fed00e109bbdn,
423
+ 0x00376886e89013f7ff4b5214d56a30d49c99f53f211a3afe01aa2bde12dn,
424
+ 0x03726870de75613c5e529e453f4d92631c03d08a7f63813e497d4cb3877n,
425
+ 0x09ce5810f1ac68810b0dffbb6beef2e0053bb937969ae7886f9d064a8c4n,
426
+ ],
427
+ },
428
+ x15: {
429
+ q: 0x3ffffffffffffffffffffffffffffffffffef90399660fc938a90165b042a7cefadb307n,
430
+ x: 0x14510d4bc44f2d26f4553942c98073c1bd35545ceabb5cc138853c5158d2729ea408836n,
431
+ s: [
432
+ 0x14cc8fcfeecd6b999b4dc6084ebb06fded0b44d5c507802cc7a5e9ecf36e69da6ae23c6n,
433
+ 0x38c9d662188982943e080b794a4cfb0732dba37c6f40d5b8cfaded6ff31c5452ba3f877n,
434
+ 0x21b7265debf90e6f988cffdb62b121a02105226c652807cc324ed6fb119a287a72680abn,
435
+ 0x20583259dc179d9da8e5387e89bff2a3090788cf1496bcabfe7d45bb120b0c811eb8980n,
436
+ ],
437
+ t: [
438
+ 0x2e5c1f00677a0e015ec3f799fa9e9a004309dbd784640eaaf5e1ce64d3045b9fe9c1fa1n,
439
+ 0x018a7d44f2b4341fefe68f6bd8894960f97e08124aab92c1ffbbe90450fcc9356c9aaa5n,
440
+ 0x3c75397ba4cf1b931877076af29f2e2f4231b117ab4b8e039f7f9704de1bd3522f150b6n,
441
+ 0x14e66b18441fa54c21e3492d0611d2b48e19de3108d915fd5ca08e786327a2675f11074n,
442
+ ],
443
+ },
444
+ x16: {
445
+ q: 0x10000000000000000000000000000000000000000000000000001e2aad6a612f33307be5fa47c3c9e052f838164cd37d9a21173n,
446
+ x: 0x0494994cc325b08e7b4ce038bd9436f90b5e59a2c13c3140cd3ae07c04a01fc489f572ce0569a6db7b8060393de76330c624177n,
447
+ s: [
448
+ 0x0c933f1dc4c70838c2ad16564715acaf545bcdd8dc203d25af3ec63949c65cb2e68ac1f60ca7eaca2a823f4e240927aa82ceec5n,
449
+ 0x08ec42d13a3909a20c41bebd2dfed8cacce56c7a7d1251df43f3e9e289dae00e239f6960924ac451e125b784cb687c7f23283fdn,
450
+ 0x0da881bce3ba851485879ef8ac585a63f1540b9198ecb8a1096d70cb25a104e2f8a96b108ae76cb49cf34491abc70e9d2aad450n,
451
+ 0x0750926ffad7ff5de85df7960b3a4f9e3d38cf5a049bfc89739c48d42b34fbee03d2c047025134cc3145b60afd22a68df0a7fb2n,
452
+ ],
453
+ t: [
454
+ 0x01adeb94c19951b460a146b8275d81638c07735b38a525d76023aaf26aa8a058590e1d5b1e78ab3c91608bda67cffbe6fc8a6ccn,
455
+ 0x06eba3d58d0e0dfc406d67fc72ef0c943624cf40019d1e48c3b54ccab0594afd5dee30aebaa22e693dbcfecad1a85d774313dadn,
456
+ 0x0a45b787db44c06deab846511eedbf7bfcfd3bd2c11d965c92fc195f67328f36a2dc83c0352885dab96b55b02fcf49dccb0e2dan,
457
+ 0x0b90f8a0e757e81d4ea6891766729c96a6d01f9aedc0d334932d1f81cc4e1973a4f01c33555ff08530a5098cadb6edae268abb5n,
458
+ ],
459
+ },
460
+ x17: {
461
+ q: 0x3ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47n,
462
+ x: 0x028a04857f24c1c082df0d909c0e72f453f2e2340ccb071f0e389bca2575da19124198c57174929ad26e348cf63f78d28021ef5a9bf2d5cbeaf6b7ccb6c4da824dd5c82cfb24e11n,
463
+ s: [
464
+ 0x2eafad4ac8644deb29095bbaa88d19f31316434f1766ad4423e0b54dd2fe0c05e307758581b0daed2902683bbc7c47b00e63e3e429ba54ea6ba3aec33a94c9a24a6ef8e27b7677an,
465
+ 0x15c2c6b7d1a070274484774e558b69fdfa193bdb7a23f27c2cd24298ce1b22a6cc9b7fb8cabfd6cf7c6b1cf3251e5a1cddd16fbfed28de79935bb2c631b8b8ea9cc4bcc937e669en,
466
+ 0x0fef0b68cb49453a4c6ecbf1708dbeefc885c57fdafb88417aaefa5b1c35017b4b498507937adce2f1d9effa5fe8f5aeb116b804fd182a6cf1518fdb62d53f60a0ff6eb707d856bn,
467
+ 0x3ff373833a06c791d7ad586afa3990f6ef76999c35246c4ad0d519bff180ca1880e11f2fb38b764854a0ae3becddb50f05ac4fcee542f207c0a6229e2e19652f0e647b9c4882193n,
468
+ ],
469
+ t: [
470
+ 0x333c711f8c62f205f926593220233b06228285261d34026232f6f729620c6de12220f282f4206d223226705608688b20b8ba86d8dfe54f07a37ec48f253283ac33c3f5102c8cc3en,
471
+ 0x328e02cf07c7b5b6d3749d8302f1ae5bfaa8f239398459af4a2c859c7727a8123a7fe9be8b228413fc8dc0e9de16af3f8f43005107f9989a5d97a5c4455da895e81336710a3fb2cn,
472
+ 0x2a77e29ead9e811a9fda0284c14cdfa1d9f8fa712da59d530a06cde54187e250ad1d4fb5788161938b8de049616399c5a56b0737c9564c9d4d845a4c6a7cdfcbff0f01a82be672en,
473
+ 0x21ce6ee4a2c72c9f93bdb3b552f4a633b8c20c200f894f008643240184be57bb282a1645e47fbbe131e899b4c61244efc2486d88cdbd1dd4a65ebdd837019d02628d0dcd6ed8fb5n,
474
+ ],
475
+ }
476
+ };
477
+ for (const v of Object.values(testVectors)) {
478
+ check(v);
479
+ }
480
+ }
481
+ /*
482
+ kk: () => {
483
+ const a = fromCurve(curve(secp192r1))
484
+ const x = 0x6FAB034934E4C0FC9AE67F5B5659A9D7D1FEFD187EE09FD4n
485
+ const m = utf8("sample")
486
+ const kk = k(a)(sha224)(x)(m)
487
+ if (kk !== 0x4381526B3FC1E7128F202E194505592F01D5FF4C5AF015D8n) { throw kk }
488
+ }
489
+ */
490
+ };
@@ -1,4 +1,4 @@
1
- import type { Reduce } from '../../types/function/operator/module.f.ts';
1
+ import type { Equal, Fold, Reduce } from '../../types/function/operator/module.f.ts';
2
2
  import { type PrimeField } from '../prime_field/module.f.ts';
3
3
  /**
4
4
  * A 2D point represented as a pair of `bigint` values `[x, y]`.
@@ -21,14 +21,14 @@ export type Init = {
21
21
  /**
22
22
  * Represents an elliptic curve and its associated operations.
23
23
  */
24
- type Curve = {
24
+ export type Curve = {
25
25
  readonly pf: PrimeField;
26
26
  readonly nf: PrimeField;
27
27
  readonly y2: (x: bigint) => bigint;
28
28
  readonly y: (x: bigint) => bigint | null;
29
29
  readonly neg: (a: Point) => Point;
30
30
  readonly add: Reduce<Point>;
31
- readonly mul: (a: Point) => (n: bigint) => Point;
31
+ readonly mul: Fold<bigint, Point>;
32
32
  };
33
33
  /**
34
34
  * Constructs an elliptic curve with the given initialization parameters.
@@ -51,7 +51,7 @@ type Curve = {
51
51
  * ```
52
52
  */
53
53
  export declare const curve: ({ p, a: [a0, a1], n }: Init) => Curve;
54
- export declare const eq: (a: Point) => (b: Point) => boolean;
54
+ export declare const eq: Equal<Point>;
55
55
  /**
56
56
  * https://neuromancer.sk/std/secg/secp192r1
57
57
  */
@@ -73,7 +73,7 @@ export const curve = ({ p, a: [a0, a1], n }) => {
73
73
  mul: repeat({ identity: null, operation: addPoint })
74
74
  };
75
75
  };
76
- export const eq = (a) => (b) => {
76
+ export const eq = a => b => {
77
77
  if (a === null || b === null) {
78
78
  return a === b;
79
79
  }
@@ -5,7 +5,7 @@ const poker = (param) => () => {
5
5
  // c ^ ((x * y) * (1/x * 1/y)) = c
6
6
  const { g, n } = param;
7
7
  const { mul, y } = curve(param);
8
- const f = (m) => (pList) => pList.map(i => mul(i)(m));
8
+ const f = (m) => (pList) => pList.map(mul(m));
9
9
  //
10
10
  const pf = prime_field(n);
11
11
  // 0 1 2 3 4 5 6 7
@@ -65,7 +65,7 @@ export default {
65
65
  // Access curve operations
66
66
  const point = c.add([1n, 1n])([2n, 5n]); // Add two points
67
67
  const negPoint = c.neg([1n, 1n]); // Negate a point
68
- const mulPoint = c.mul([1n, 1n])(3n); // Multiply a point by 3
68
+ const mulPoint = c.mul(3n)([1n, 1n]); // Multiply a point by 3
69
69
  },
70
70
  test: () => {
71
71
  const test_curve = c => {
@@ -87,23 +87,23 @@ export default {
87
87
  point_check(g);
88
88
  point_check(neg(g));
89
89
  const test_mul = (p) => {
90
- if (mul(p)(0n) !== null) {
90
+ if (mul(0n)(p) !== null) {
91
91
  throw 'O';
92
92
  }
93
- if (mul(p)(1n) !== p) {
93
+ if (mul(1n)(p) !== p) {
94
94
  throw 'p';
95
95
  }
96
- if (mul(p)(n) !== null) {
96
+ if (mul(n)(p) !== null) {
97
97
  throw 'n';
98
98
  }
99
99
  const pn = neg(p);
100
- if (!eq(mul(p)(n - 1n))(pn)) {
100
+ if (!eq(mul(n - 1n)(p))(pn)) {
101
101
  throw 'n - 1';
102
102
  }
103
103
  const f = s => {
104
- const r = mul(p)(s);
104
+ const r = mul(s)(p);
105
105
  point_check(r);
106
- const rn = mul(pn)(s);
106
+ const rn = mul(s)(pn);
107
107
  point_check(rn);
108
108
  if (!eq(r)(neg(rn))) {
109
109
  throw 'r != -rn';
@@ -1,5 +1,11 @@
1
+ /**
2
+ * See https://www.rfc-editor.org/rfc/rfc6234
3
+ *
4
+ * @module
5
+ */
1
6
  import type { Array16, Array8 } from '../../types/array/module.f.ts';
2
7
  import { type Vec } from '../../types/bit_vec/module.f.ts';
8
+ import type { Fold } from '../../types/function/operator/module.f.ts';
3
9
  import { type List } from '../../types/list/module.f.ts';
4
10
  export type V8 = Array8<bigint>;
5
11
  export type V16 = Array16<bigint>;
@@ -25,8 +31,8 @@ export type Base = {
25
31
  readonly chunkLength: bigint;
26
32
  readonly compress: (i: V8) => (u: bigint) => V8;
27
33
  readonly fromV8: (a: V8) => bigint;
28
- readonly append: (state: State) => (v: Vec) => State;
29
- readonly end: (hashLength: bigint) => (state: State) => bigint;
34
+ readonly append: Fold<Vec, State>;
35
+ readonly end: (hashLength: bigint) => (state: State) => Vec;
30
36
  };
31
37
  /**
32
38
  * SHA2. See https://en.wikipedia.org/wiki/SHA-2
@@ -56,18 +62,18 @@ export type Sha2 = {
56
62
  /**
57
63
  * Appends data to the state and returns the new state.
58
64
  *
59
- * @param state The current state.
60
65
  * @param v The data to append.
66
+ * @param state The current state.
61
67
  * @returns The new state after appending data.
62
68
  */
63
- readonly append: (state: State) => (v: Vec) => State;
69
+ readonly append: Fold<Vec, State>;
64
70
  /**
65
71
  * Finalizes the hash and returns the result as a bigint.
66
72
  *
67
73
  * @param state The final state.
68
74
  * @returns The resulting hash.
69
75
  */
70
- readonly end: (state: State) => bigint;
76
+ readonly end: (state: State) => Vec;
71
77
  };
72
78
  export declare const computeSync: ({ append, init, end }: Sha2) => (list: List<Vec>) => Vec;
73
79
  export declare const base32: Base;
@@ -115,13 +115,14 @@ const base = ({ logBitLen, k, bs0, bs1, ss0, ss1 }) => {
115
115
  };
116
116
  const chunkLength = bitLength << 4n; // * 16
117
117
  const fromV8 = (a) => a.reduce((p, v) => (p << bitLength) | v);
118
- const lastChunkLength = chunkLength - 65n;
118
+ // See https://www.rfc-editor.org/rfc/rfc6234#section-4
119
+ const lastChunkLength = chunkLength - 1n - (bitLength << 1n);
119
120
  return {
120
121
  bitLength,
121
122
  chunkLength,
122
123
  compress,
123
124
  fromV8,
124
- append: (state) => (v) => {
125
+ append: (v) => (state) => {
125
126
  let { remainder, hash, len } = state;
126
127
  remainder = concat(remainder)(v);
127
128
  let remainderLen = length(remainder);
@@ -168,7 +169,7 @@ const sha2 = ({ append, end, chunkLength }, hash, hashLength) => ({
168
169
  end: end(hashLength),
169
170
  });
170
171
  export const computeSync = ({ append, init, end }) => {
171
- const f = fold(flip(append))(init);
172
+ const f = fold(append)(init);
172
173
  return (list) => end(f(list));
173
174
  };
174
175
  export const base32 = base({
@@ -6,7 +6,7 @@ declare const _default: {
6
6
  };
7
7
  b64: () => {
8
8
  s512: () => void;
9
- s385: () => void;
9
+ s384: () => void;
10
10
  s512x256: () => void;
11
11
  s512x224: () => void;
12
12
  };
@@ -24,5 +24,8 @@ declare const _default: {
24
24
  8: () => void;
25
25
  16: () => void;
26
26
  };
27
+ padding: {
28
+ overflow: () => void;
29
+ };
27
30
  };
28
31
  export default _default;