functionalscript 0.0.550 → 0.0.552
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 +1 -1
- package/prime_field/module.f.cjs +2 -19
- package/secp/module.f.cjs +3 -2
- package/types/bigint/module.f.cjs +31 -1
package/package.json
CHANGED
package/prime_field/module.f.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const op = require('../types/function/operator/module.f.cjs')
|
|
2
|
+
const { scalar_mul } = require('../types/bigint/module.f.cjs')
|
|
2
3
|
|
|
3
4
|
/** @typedef {op.Reduce<bigint>} Reduce */
|
|
4
5
|
|
|
@@ -22,23 +23,6 @@ const op = require('../types/function/operator/module.f.cjs')
|
|
|
22
23
|
* }} PrimeField
|
|
23
24
|
*/
|
|
24
25
|
|
|
25
|
-
/** @type {<T>(zero: T, add: op.Reduce<T>) => (a: T) => (n: bigint) => T} */
|
|
26
|
-
const scalar_mul = (zero, add) => a => n => {
|
|
27
|
-
let ai = a
|
|
28
|
-
let ni = n
|
|
29
|
-
let result = zero
|
|
30
|
-
while (true) {
|
|
31
|
-
if ((ni & 1n) === 1n) {
|
|
32
|
-
result = add(result)(ai)
|
|
33
|
-
}
|
|
34
|
-
ni >>= 1n
|
|
35
|
-
if (ni === 0n) {
|
|
36
|
-
return result
|
|
37
|
-
}
|
|
38
|
-
ai = add(ai)(ai)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
26
|
/** @type {(p: bigint) => PrimeField} */
|
|
43
27
|
const prime_field = p => {
|
|
44
28
|
/** @type {Reduce} */
|
|
@@ -70,7 +54,7 @@ const prime_field = p => {
|
|
|
70
54
|
/** @type {Unary} */
|
|
71
55
|
const pow2 = a => mul(a)(a)
|
|
72
56
|
/** @type {Reduce} */
|
|
73
|
-
const pow = scalar_mul(1n, mul)
|
|
57
|
+
const pow = scalar_mul({ 0: 1n, add: mul })
|
|
74
58
|
return {
|
|
75
59
|
p,
|
|
76
60
|
middle,
|
|
@@ -92,7 +76,6 @@ const prime_field = p => {
|
|
|
92
76
|
}
|
|
93
77
|
|
|
94
78
|
module.exports = {
|
|
95
|
-
scalar_mul,
|
|
96
79
|
prime_field,
|
|
97
80
|
/** @type {(f: PrimeField) => (a: bigint) => bigint|null} */
|
|
98
81
|
sqrt: ({p, mul, pow }) => {
|
package/secp/module.f.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const op = require('../types/function/operator/module.f.cjs')
|
|
2
2
|
const pf = require('../prime_field/module.f.cjs')
|
|
3
|
-
const { scalar_mul
|
|
3
|
+
const { scalar_mul } = require('../types/bigint/module.f.cjs')
|
|
4
|
+
const { prime_field, sqrt } = pf
|
|
4
5
|
|
|
5
6
|
/** @typedef {readonly[bigint, bigint]} Point2D */
|
|
6
7
|
|
|
@@ -78,7 +79,7 @@ const curve = ({ p, a: [a0, a1], n }) => {
|
|
|
78
79
|
return [x, neg(y)]
|
|
79
80
|
},
|
|
80
81
|
add: addPoint,
|
|
81
|
-
mul: scalar_mul(null, addPoint)
|
|
82
|
+
mul: scalar_mul({ 0: null, add: addPoint })
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
const compare = require('../function/compare/module.f.cjs')
|
|
2
|
+
const op = require('../function/operator/module.f.cjs')
|
|
2
3
|
const { unsafeCmp } = compare
|
|
3
4
|
const { reduce } = require('../list/module.f.cjs')
|
|
4
5
|
|
|
6
|
+
/** @typedef {op.Unary<bigint, bigint>} Unary*/
|
|
7
|
+
|
|
5
8
|
/** @type {(a: bigint) => (b: bigint) => bigint} */
|
|
6
9
|
const addition = a => b => a + b
|
|
7
10
|
|
|
@@ -16,6 +19,31 @@ const sign = a => unsafeCmp(a)(0n)
|
|
|
16
19
|
/** @type {(a: bigint) => string} */
|
|
17
20
|
const serialize = a => `${a}n`
|
|
18
21
|
|
|
22
|
+
/**
|
|
23
|
+
* @template T
|
|
24
|
+
* @typedef {{
|
|
25
|
+
* readonly 0: T
|
|
26
|
+
* readonly add: op.Reduce<T>
|
|
27
|
+
* }} Additive
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** @type {<T>(a: Additive<T>) => (a: T) => (n: bigint) => T} */
|
|
31
|
+
const scalar_mul = ({ 0: _0, add }) => a => n => {
|
|
32
|
+
let ai = a
|
|
33
|
+
let ni = n
|
|
34
|
+
let result = _0
|
|
35
|
+
while (true) {
|
|
36
|
+
if ((ni & 1n) === 1n) {
|
|
37
|
+
result = add(result)(ai)
|
|
38
|
+
}
|
|
39
|
+
ni >>= 1n
|
|
40
|
+
if (ni === 0n) {
|
|
41
|
+
return result
|
|
42
|
+
}
|
|
43
|
+
ai = add(ai)(ai)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
19
47
|
module.exports = {
|
|
20
48
|
/** @readonly */
|
|
21
49
|
addition,
|
|
@@ -27,4 +55,6 @@ module.exports = {
|
|
|
27
55
|
sign,
|
|
28
56
|
/** @readonly */
|
|
29
57
|
serialize,
|
|
30
|
-
|
|
58
|
+
/** @readonly */
|
|
59
|
+
scalar_mul,
|
|
60
|
+
}
|