functionalscript 0.1.608 → 0.2.0
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 +10 -0
- package/Cargo.lock +4 -0
- package/Cargo.toml +4 -2
- package/README.md +1 -1
- package/com/cpp/module.f.d.mts +4 -8
- package/com/cpp/module.f.mjs +20 -25
- package/com/cpp/testlib.f.mjs +3 -4
- package/com/cs/module.f.d.mts +4 -8
- package/com/cs/module.f.mjs +18 -23
- package/com/cs/testlib.f.mjs +3 -5
- package/com/rust/module.f.d.mts +3 -7
- package/com/rust/module.f.mjs +25 -30
- package/com/rust/nanocom/src/cobject.rs +1 -1
- package/com/rust/testlib.f.mjs +3 -5
- package/com/test/build.f.d.mts +2 -2
- package/com/test/build.f.mjs +2 -2
- package/com/test/build.mjs +4 -4
- package/com/test/rust/src/lib.rs +4 -4
- package/com/types/module.f.d.mts +5 -10
- package/com/types/module.f.mjs +5 -12
- package/commonjs/build/module.f.d.mts +13 -17
- package/commonjs/build/module.f.mjs +23 -28
- package/commonjs/build/test.f.mjs +4 -4
- package/commonjs/module/function/module.f.d.mts +0 -2
- package/commonjs/module/function/module.f.mjs +0 -2
- package/commonjs/module/module.f.d.mts +16 -21
- package/commonjs/module/module.f.mjs +2 -9
- package/commonjs/module.d.mts +1 -5
- package/commonjs/module.f.d.mts +0 -2
- package/commonjs/module.f.mjs +0 -2
- package/commonjs/module.mjs +2 -7
- package/commonjs/package/dependencies/module.f.d.mts +3 -7
- package/commonjs/package/dependencies/module.f.mjs +5 -10
- package/commonjs/package/dependencies/test.f.mjs +1 -1
- package/commonjs/package/module.f.d.mts +12 -18
- package/commonjs/package/module.f.mjs +6 -13
- package/commonjs/package/test.f.mjs +1 -1
- package/commonjs/path/module.f.d.mts +25 -32
- package/commonjs/path/module.f.mjs +12 -23
- package/commonjs/path/test.f.mjs +11 -11
- package/commonjs/test.mjs +1 -1
- package/dev/module.f.d.mts +1 -4
- package/dev/module.f.mjs +1 -4
- package/dev/module.mjs +1 -1
- package/dev/test/module.f.d.mts +2 -3
- package/dev/test/module.f.mjs +5 -7
- package/djs/module.f.d.mts +13 -18
- package/djs/module.f.mjs +12 -19
- package/djs/parser/module.f.d.mts +53 -37
- package/djs/parser/module.f.mjs +278 -131
- package/djs/parser/test.f.d.mts +4 -0
- package/djs/parser/test.f.mjs +186 -70
- package/djs/test.f.mjs +4 -4
- package/djs/tokenizer/module.f.d.mts +6 -10
- package/djs/tokenizer/module.f.mjs +19 -22
- package/djs/tokenizer/test.f.mjs +7 -7
- package/doc/LANGUAGE.md +17 -16
- package/doc/README.md +14 -50
- package/fsc/README.md +0 -3
- package/fsc/module.f.d.mts +4 -9
- package/fsc/module.f.mjs +17 -24
- package/fsc/test.f.mjs +3 -3
- package/fsm/README.md +1 -1
- package/fsm/module.f.d.mts +13 -20
- package/fsm/module.f.mjs +27 -38
- package/fsm/test.f.mjs +8 -8
- package/html/README.md +24 -0
- package/html/module.f.d.mts +7 -12
- package/html/module.f.mjs +14 -23
- package/html/test.f.mjs +4 -4
- package/issues/01-test-debug.md +3 -0
- package/issues/{publish.md → 05-publish.md} +8 -8
- package/issues/17-djs-extension.md +6 -0
- package/issues/README.md +20 -13
- package/issues/lang/1000-json.md +38 -0
- package/issues/lang/2110-default-export.md +2 -2
- package/issues/lang/2310-undefined.md +1 -1
- package/issues/lang/2330-property-accessor.md +225 -0
- package/issues/lang/2360-built-in.md +54 -47
- package/issues/lang/3240-export.md +44 -0
- package/issues/lang/README.md +64 -22
- package/issues/test.f.d.mts +16 -0
- package/issues/test.f.mjs +57 -0
- package/js/tokenizer/module.f.d.mts +18 -17
- package/js/tokenizer/module.f.mjs +80 -61
- package/js/tokenizer/test.f.mjs +15 -12
- package/json/module.f.d.mts +18 -26
- package/json/module.f.mjs +18 -31
- package/json/parser/module.f.d.mts +9 -13
- package/json/parser/module.f.mjs +9 -14
- package/json/parser/test.f.mjs +7 -7
- package/json/serializer/module.f.d.mts +11 -20
- package/json/serializer/module.f.mjs +14 -29
- package/json/serializer/test.f.mjs +2 -2
- package/json/test.f.mjs +3 -3
- package/json/tokenizer/module.f.d.mts +6 -10
- package/json/tokenizer/module.f.mjs +16 -20
- package/json/tokenizer/test.f.mjs +6 -6
- package/jsr.json +1 -1
- package/nanvm-lib/Cargo.toml +6 -0
- package/nanvm-lib/src/extension.rs +119 -0
- package/nanvm-lib/src/interface.rs +136 -0
- package/nanvm-lib/src/lib.rs +7 -0
- package/nanvm-lib/src/naive.rs +229 -0
- package/nanvm-lib/src/nanenum.rs +230 -0
- package/nanvm-lib/src/nullish.rs +7 -0
- package/nanvm-lib/src/sign.rs +5 -0
- package/nanvm-lib/src/simple.rs +32 -0
- package/nanvm-lib/tests/test.f.d.mts +36 -0
- package/nanvm-lib/tests/test.f.mjs +79 -0
- package/nanvm-lib/tests/test.rs +108 -0
- package/nodejs/version/main.mjs +1 -1
- package/nodejs/version/module.f.d.mts +4 -9
- package/nodejs/version/module.f.mjs +2 -7
- package/nodejs/version/test.f.mjs +3 -3
- package/package.json +1 -1
- package/prime_field/module.f.d.mts +20 -23
- package/prime_field/module.f.mjs +9 -12
- package/prime_field/test.f.mjs +1 -1
- package/secp/module.f.d.mts +27 -28
- package/secp/module.f.mjs +38 -39
- package/secp/test.f.mjs +4 -4
- package/sha2/module.f.d.mts +8 -16
- package/sha2/module.f.mjs +7 -20
- package/sha2/test.f.mjs +4 -4
- package/text/README.md +2 -2
- package/text/ascii/module.f.d.mts +69 -72
- package/text/ascii/module.f.mjs +5 -10
- package/text/ascii/test.f.mjs +3 -3
- package/text/module.f.d.mts +9 -14
- package/text/module.f.mjs +7 -14
- package/text/sgr/module.f.d.mts +7 -9
- package/text/sgr/module.f.mjs +2 -4
- package/text/test.f.mjs +3 -3
- package/text/utf16/module.f.d.mts +8 -15
- package/text/utf16/module.f.mjs +17 -28
- package/text/utf16/test.f.mjs +5 -5
- package/text/utf8/module.f.d.mts +4 -9
- package/text/utf8/module.f.mjs +9 -16
- package/text/utf8/test.f.mjs +4 -4
- package/types/array/module.f.d.mts +14 -24
- package/types/array/module.f.mjs +8 -25
- package/types/array/test.f.mjs +3 -3
- package/types/bigfloat/module.f.d.mts +4 -9
- package/types/bigfloat/module.f.mjs +3 -10
- package/types/bigfloat/test.f.mjs +1 -1
- package/types/bigint/module.f.d.mts +16 -64
- package/types/bigint/module.f.mjs +11 -30
- package/types/bigint/test.f.mjs +1 -1
- package/types/btree/find/module.f.d.mts +20 -26
- package/types/btree/find/module.f.mjs +8 -17
- package/types/btree/find/test.f.mjs +7 -7
- package/types/btree/module.f.d.mts +4 -8
- package/types/btree/module.f.mjs +6 -11
- package/types/btree/remove/module.f.d.mts +7 -12
- package/types/btree/remove/module.f.mjs +10 -17
- package/types/btree/remove/test.f.mjs +5 -5
- package/types/btree/set/module.f.d.mts +3 -7
- package/types/btree/set/module.f.mjs +4 -9
- package/types/btree/set/test.f.mjs +4 -4
- package/types/btree/test.f.mjs +9 -9
- package/types/btree/types/module.f.d.mts +0 -2
- package/types/btree/types/module.f.mjs +0 -2
- package/types/byte_set/module.f.d.mts +16 -29
- package/types/byte_set/module.f.mjs +14 -39
- package/types/byte_set/test.f.mjs +5 -5
- package/types/function/compare/module.f.d.mts +9 -15
- package/types/function/compare/module.f.mjs +3 -12
- package/types/function/compare/test.f.mjs +1 -1
- package/types/function/module.f.d.mts +20 -27
- package/types/function/module.f.mjs +4 -15
- package/types/function/operator/module.f.d.mts +28 -43
- package/types/function/operator/module.f.mjs +14 -41
- package/types/function/test.f.mjs +1 -1
- package/types/list/module.f.d.mts +56 -91
- package/types/list/module.f.mjs +45 -114
- package/types/list/test.f.mjs +10 -10
- package/types/map/module.f.d.mts +15 -24
- package/types/map/module.f.mjs +15 -30
- package/types/map/test.f.mjs +2 -2
- package/types/nibble_set/module.f.d.mts +10 -20
- package/types/nibble_set/module.f.mjs +7 -24
- package/types/nibble_set/test.f.mjs +2 -2
- package/types/nullable/module.f.d.mts +3 -8
- package/types/nullable/module.f.mjs +2 -9
- package/types/nullable/test.f.mjs +1 -1
- package/types/number/module.f.d.mts +7 -13
- package/types/number/module.f.mjs +8 -19
- package/types/number/test.f.mjs +1 -1
- package/types/object/module.f.d.mts +11 -18
- package/types/object/module.f.mjs +9 -20
- package/types/object/test.f.mjs +1 -1
- package/types/range/module.f.d.mts +3 -8
- package/types/range/module.f.mjs +2 -9
- package/types/range/test.f.mjs +1 -1
- package/types/range_map/module.f.d.mts +9 -15
- package/types/range_map/module.f.mjs +9 -18
- package/types/range_map/test.f.mjs +32 -32
- package/types/result/module.d.mts +3 -3
- package/types/result/module.f.d.mts +6 -12
- package/types/result/module.f.mjs +3 -12
- package/types/result/module.mjs +2 -2
- package/types/sorted_list/module.f.d.mts +22 -28
- package/types/sorted_list/module.f.mjs +10 -19
- package/types/sorted_list/test.f.mjs +7 -7
- package/types/sorted_set/module.f.d.mts +6 -12
- package/types/sorted_set/module.f.mjs +7 -16
- package/types/sorted_set/test.f.mjs +7 -7
- package/types/string/module.f.d.mts +8 -14
- package/types/string/module.f.mjs +10 -21
- package/types/string/test.f.mjs +2 -2
- package/types/string_set/module.f.d.mts +8 -16
- package/types/string_set/module.f.mjs +12 -27
- package/types/string_set/test.f.mjs +1 -1
- package/issues/lang/2351-property-accessor.md +0 -44
- package/issues/lang/2352-property-call.md +0 -43
- package/issues/lang/2353-property-at.md +0 -19
- package/issues/test-debug.md +0 -12
- /package/issues/{esm.md → 02-esm.md} +0 -0
- /package/issues/{djs.md → 03-djs.md} +0 -0
- /package/issues/{fs-load.md → 11-fs-load.md} +0 -0
- /package/issues/lang/{2330-grouping.md → 2350-grouping.md} +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** @type {(a: unknown) => (b: unknown) => void} */
|
|
2
|
+
const e = a => b => {
|
|
3
|
+
if (a === b) { } else { throw [a, '===', b] }
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** @type {(a: unknown) => (b: unknown) => void} */
|
|
7
|
+
const n = a => b => {
|
|
8
|
+
if (a !== b) { } else { throw [a, '!==', b] }
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
eq: {
|
|
13
|
+
nullish: () => {
|
|
14
|
+
e(null)(null)
|
|
15
|
+
e(undefined)(undefined)
|
|
16
|
+
n(null)(undefined)
|
|
17
|
+
},
|
|
18
|
+
boolean: {
|
|
19
|
+
boolean: () => {
|
|
20
|
+
e(true)(true)
|
|
21
|
+
e(false)(false)
|
|
22
|
+
n(true)(false)
|
|
23
|
+
},
|
|
24
|
+
nullish: () => {
|
|
25
|
+
n(false)(undefined)
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
number: {
|
|
29
|
+
number: () => {
|
|
30
|
+
e(2.3)(2.3)
|
|
31
|
+
n(2.3)(-5.4)
|
|
32
|
+
n(NaN)(NaN)
|
|
33
|
+
e(0)(-0)
|
|
34
|
+
if (!Object.is(-0, -0)) { throw -0 }
|
|
35
|
+
if (Object.is(0, -0)) { throw -0 }
|
|
36
|
+
e(Infinity)(Infinity)
|
|
37
|
+
e(-Infinity)(-Infinity)
|
|
38
|
+
n(Infinity)(-Infinity)
|
|
39
|
+
},
|
|
40
|
+
nullish: () => {
|
|
41
|
+
n(undefined)(NaN)
|
|
42
|
+
n(undefined)(0)
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
string: {
|
|
46
|
+
string: () => {
|
|
47
|
+
e("hello")("hello")
|
|
48
|
+
n("hello")("world")
|
|
49
|
+
},
|
|
50
|
+
number: () => {
|
|
51
|
+
n(0)("0")
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
bigint: {
|
|
55
|
+
bigint: () => {
|
|
56
|
+
e(12n)(12n)
|
|
57
|
+
n(12n)(-12n)
|
|
58
|
+
n(12n)(13n)
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
array: {
|
|
62
|
+
array: () => {
|
|
63
|
+
/** @type {any} */
|
|
64
|
+
const a = []
|
|
65
|
+
e(a)(a)
|
|
66
|
+
n([])([])
|
|
67
|
+
const a0 = ['0']
|
|
68
|
+
e(a0)(a0)
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
object: {
|
|
72
|
+
object: () => {
|
|
73
|
+
const o = { '0': '0' }
|
|
74
|
+
e(o)(o)
|
|
75
|
+
n(o)({ '0': '0' })
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
use nanvm_lib::{interface::{Complex, Container, Extension, Any, Utf8}, naive, nullish::Nullish, sign::Sign, simple::Simple};
|
|
2
|
+
|
|
3
|
+
fn eq<A: Any>() {
|
|
4
|
+
// nullish
|
|
5
|
+
let null0: A = Simple::Nullish(Nullish::Null).to_unknown();
|
|
6
|
+
let null1 = Simple::Nullish(Nullish::Null).to_unknown();
|
|
7
|
+
let undefined0 = Simple::Nullish(Nullish::Undefined).to_unknown();
|
|
8
|
+
let undefined1 = Simple::Nullish(Nullish::Undefined).to_unknown();
|
|
9
|
+
{
|
|
10
|
+
assert_eq!(null0, null1);
|
|
11
|
+
assert_eq!(undefined0, undefined1);
|
|
12
|
+
assert_ne!(null1, undefined0);
|
|
13
|
+
}
|
|
14
|
+
// boolean
|
|
15
|
+
let true0: A = Simple::Boolean(true).to_unknown();
|
|
16
|
+
let true1 = Simple::Boolean(true).to_unknown();
|
|
17
|
+
let false0 = Simple::Boolean(false).to_unknown();
|
|
18
|
+
let false1 = Simple::Boolean(false).to_unknown();
|
|
19
|
+
{
|
|
20
|
+
// boolean
|
|
21
|
+
{
|
|
22
|
+
assert_eq!(true0, true1);
|
|
23
|
+
assert_eq!(false0, false1);
|
|
24
|
+
assert_ne!(true0, false0);
|
|
25
|
+
}
|
|
26
|
+
// nullish
|
|
27
|
+
{
|
|
28
|
+
assert_ne!(false0, undefined0);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// number
|
|
32
|
+
let number00: A = Simple::Number(2.3).to_unknown();
|
|
33
|
+
let number01: A = Simple::Number(2.3).to_unknown();
|
|
34
|
+
let number1: A = Simple::Number(-5.4).to_unknown();
|
|
35
|
+
let number_nan: A = Simple::Number(f64::NAN).to_unknown();
|
|
36
|
+
let number_p0: A = Simple::Number(0.0).to_unknown();
|
|
37
|
+
let number_n0: A = Simple::Number(-0.0).to_unknown();
|
|
38
|
+
let number_p_inf0: A = Simple::Number(f64::INFINITY).to_unknown();
|
|
39
|
+
let number_p_inf1: A = Simple::Number(f64::INFINITY).to_unknown();
|
|
40
|
+
let number_n_inf0: A = Simple::Number(-f64::INFINITY).to_unknown();
|
|
41
|
+
let number_n_inf1: A = Simple::Number(-f64::INFINITY).to_unknown();
|
|
42
|
+
{
|
|
43
|
+
// number
|
|
44
|
+
{
|
|
45
|
+
assert_eq!(number00, number01);
|
|
46
|
+
assert_ne!(number00, number1);
|
|
47
|
+
assert_ne!(number_nan, number_nan);
|
|
48
|
+
assert_eq!(number_p0, number_n0);
|
|
49
|
+
// Object.is()
|
|
50
|
+
assert_eq!((-0f64).to_bits(), (-0f64).to_bits());
|
|
51
|
+
assert_ne!(0f64.to_bits(), (-0f64).to_bits());
|
|
52
|
+
assert_eq!(number_p_inf0, number_p_inf1);
|
|
53
|
+
assert_eq!(number_n_inf0, number_n_inf1);
|
|
54
|
+
assert_ne!(number_p_inf0, number_n_inf0);
|
|
55
|
+
}
|
|
56
|
+
// nullish
|
|
57
|
+
{
|
|
58
|
+
assert_ne!(number_nan, undefined0);
|
|
59
|
+
assert_ne!(number00, undefined0);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// string
|
|
63
|
+
let string_hello0: A = "Hello!".to_unknown();
|
|
64
|
+
let string_hello1: A = "Hello!".to_unknown();
|
|
65
|
+
let string_world0: A = "world!".to_unknown();
|
|
66
|
+
let string0: A = "0".to_unknown();
|
|
67
|
+
let s0 = "0".to_string16::<A>();
|
|
68
|
+
{
|
|
69
|
+
{
|
|
70
|
+
assert_eq!(string_hello0, string_hello1);
|
|
71
|
+
assert_ne!(string_hello0, string_world0);
|
|
72
|
+
}
|
|
73
|
+
{
|
|
74
|
+
assert_ne!(number_p0, string0.clone());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// bigint
|
|
78
|
+
let bigint12_0: A = A::BigInt::new(Sign::Positive, [12]).to_unknown();
|
|
79
|
+
let bigint12_1: A = A::BigInt::new(Sign::Positive, [12]).to_unknown();
|
|
80
|
+
let bigint12m: A = A::BigInt::new(Sign::Negative, [12]).to_unknown();
|
|
81
|
+
let bigint13: A = A::BigInt::new(Sign::Positive, [13]).to_unknown();
|
|
82
|
+
{
|
|
83
|
+
assert_eq!(bigint12_0, bigint12_1);
|
|
84
|
+
assert_ne!(bigint12_0, bigint12m);
|
|
85
|
+
assert_ne!(bigint12_0, bigint13);
|
|
86
|
+
}
|
|
87
|
+
// array
|
|
88
|
+
let array0: A = [].to_array_unknown();
|
|
89
|
+
let array1: A = [].to_array_unknown();
|
|
90
|
+
let array2: A = [string0.clone()].to_array_unknown();
|
|
91
|
+
{
|
|
92
|
+
assert_eq!(array0, array0);
|
|
93
|
+
assert_ne!(array0, array1);
|
|
94
|
+
assert_eq!(array2, array2);
|
|
95
|
+
}
|
|
96
|
+
// object
|
|
97
|
+
let object0: A = [(s0.clone(), string0.clone())].to_object_unknown();
|
|
98
|
+
let object1: A = [(s0, string0)].to_object_unknown();
|
|
99
|
+
{
|
|
100
|
+
assert_eq!(object0, object0);
|
|
101
|
+
assert_ne!(object0, object1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
#[test]
|
|
106
|
+
fn naive_eq() {
|
|
107
|
+
eq::<naive::Any>();
|
|
108
|
+
}
|
package/nodejs/version/main.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export default _default;
|
|
1
|
+
/** @type {<T>(fs: Fs<T>) => string} */
|
|
2
|
+
export const getVersion: <T>(fs: Fs<T>) => string;
|
|
3
|
+
/** @type {<T>(node: Node<T>) => readonly[T, T]} */
|
|
4
|
+
export const updateVersion: <T>(node: Node<T>) => readonly [T, T];
|
|
6
5
|
export type Buffer = {};
|
|
7
6
|
export type Fs<T> = {
|
|
8
7
|
readonly readFileSync: (name: string) => Buffer;
|
|
@@ -11,7 +10,3 @@ export type Fs<T> = {
|
|
|
11
10
|
export type Node<T> = {
|
|
12
11
|
readonly fs: Fs<T>;
|
|
13
12
|
};
|
|
14
|
-
/** @type {<T>(fs: Fs<T>) => string} */
|
|
15
|
-
declare const getVersion: <T>(fs: Fs<T>) => string;
|
|
16
|
-
/** @type {<T>(node: Node<T>) => readonly[T, T]} */
|
|
17
|
-
declare const updateVersion: <T>(node: Node<T>) => readonly [T, T];
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
const { stringify, parse } = JSON
|
|
21
21
|
|
|
22
22
|
/** @type {<T>(fs: Fs<T>) => string} */
|
|
23
|
-
const getVersion = fs => readJson(fs)('package').version
|
|
23
|
+
export const getVersion = fs => readJson(fs)('package').version
|
|
24
24
|
|
|
25
25
|
const jsonFile = (/** @type {string} */jsonFile) => `${jsonFile}.json`
|
|
26
26
|
|
|
@@ -28,7 +28,7 @@ const jsonFile = (/** @type {string} */jsonFile) => `${jsonFile}.json`
|
|
|
28
28
|
const readJson = fs => name => parse(fs.readFileSync(jsonFile(name)).toString())
|
|
29
29
|
|
|
30
30
|
/** @type {<T>(node: Node<T>) => readonly[T, T]} */
|
|
31
|
-
const updateVersion = ({ fs }) => {
|
|
31
|
+
export const updateVersion = ({ fs }) => {
|
|
32
32
|
const f = (/** @type {string} */name) => {
|
|
33
33
|
return fs.writeFileSync(
|
|
34
34
|
jsonFile(name),
|
|
@@ -45,8 +45,3 @@ const updateVersion = ({ fs }) => {
|
|
|
45
45
|
f('jsr')
|
|
46
46
|
]
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
export default {
|
|
50
|
-
getVersion,
|
|
51
|
-
updateVersion,
|
|
52
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _ from './module.f.mjs'
|
|
2
2
|
|
|
3
3
|
const version = '0.3.0'
|
|
4
4
|
|
|
@@ -82,13 +82,13 @@ const e = '{\n' +
|
|
|
82
82
|
' }\n' +
|
|
83
83
|
'}'
|
|
84
84
|
|
|
85
|
-
/** @type {(s: string) =>
|
|
85
|
+
/** @type {(s: string) => _.Buffer} */
|
|
86
86
|
const buffer = s => ({
|
|
87
87
|
toString: () => s
|
|
88
88
|
})
|
|
89
89
|
|
|
90
90
|
export default () => {
|
|
91
|
-
/** @type {
|
|
91
|
+
/** @type {_.Node<string>} */
|
|
92
92
|
const node = {
|
|
93
93
|
fs: {
|
|
94
94
|
readFileSync: n => buffer(JSON.stringify(x[n])),
|
package/package.json
CHANGED
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
declare namespace _default {
|
|
2
|
-
export { prime_field };
|
|
3
|
-
export let sqrt: (f: PrimeField) => (a: bigint) => bigint | null;
|
|
4
|
-
}
|
|
5
|
-
export default _default;
|
|
6
|
-
export type Reduce = Operator.Reduce<bigint>;
|
|
7
|
-
export type Unary = Operator.Unary<bigint, bigint>;
|
|
8
|
-
export type PrimeField = {
|
|
9
|
-
readonly p: bigint;
|
|
10
|
-
readonly middle: bigint;
|
|
11
|
-
readonly max: bigint;
|
|
12
|
-
readonly neg: Unary;
|
|
13
|
-
readonly sub: Reduce;
|
|
14
|
-
readonly add: Reduce;
|
|
15
|
-
readonly abs: Unary;
|
|
16
|
-
readonly mul: Reduce;
|
|
17
|
-
readonly reciprocal: Unary;
|
|
18
|
-
readonly div: Reduce;
|
|
19
|
-
readonly pow: Reduce;
|
|
20
|
-
readonly pow2: Unary;
|
|
21
|
-
readonly pow3: Unary;
|
|
22
|
-
};
|
|
23
1
|
/** @typedef {Operator.Reduce<bigint>} Reduce */
|
|
24
2
|
/** @typedef {Operator.Unary<bigint, bigint>} Unary*/
|
|
25
3
|
/**
|
|
@@ -40,5 +18,24 @@ export type PrimeField = {
|
|
|
40
18
|
* }} PrimeField
|
|
41
19
|
*/
|
|
42
20
|
/** @type {(p: bigint) => PrimeField} */
|
|
43
|
-
|
|
21
|
+
export const prime_field: (p: bigint) => PrimeField;
|
|
22
|
+
/** @type {(f: PrimeField) => (a: bigint) => bigint|null} */
|
|
23
|
+
export const sqrt: (f: PrimeField) => (a: bigint) => bigint | null;
|
|
24
|
+
export type Reduce = Operator.Reduce<bigint>;
|
|
25
|
+
export type Unary = Operator.Unary<bigint, bigint>;
|
|
26
|
+
export type PrimeField = {
|
|
27
|
+
readonly p: bigint;
|
|
28
|
+
readonly middle: bigint;
|
|
29
|
+
readonly max: bigint;
|
|
30
|
+
readonly neg: Unary;
|
|
31
|
+
readonly sub: Reduce;
|
|
32
|
+
readonly add: Reduce;
|
|
33
|
+
readonly abs: Unary;
|
|
34
|
+
readonly mul: Reduce;
|
|
35
|
+
readonly reciprocal: Unary;
|
|
36
|
+
readonly div: Reduce;
|
|
37
|
+
readonly pow: Reduce;
|
|
38
|
+
readonly pow2: Unary;
|
|
39
|
+
readonly pow3: Unary;
|
|
40
|
+
};
|
|
44
41
|
import * as Operator from '../types/function/operator/module.f.mjs';
|
package/prime_field/module.f.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
2
|
import * as Operator from '../types/function/operator/module.f.mjs'
|
|
3
|
-
import bi from '../types/bigint/module.f.mjs'
|
|
3
|
+
import * as bi from '../types/bigint/module.f.mjs'
|
|
4
4
|
const { scalar_mul } = bi
|
|
5
5
|
|
|
6
6
|
/** @typedef {Operator.Reduce<bigint>} Reduce */
|
|
@@ -26,7 +26,7 @@ const { scalar_mul } = bi
|
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
/** @type {(p: bigint) => PrimeField} */
|
|
29
|
-
const prime_field = p => {
|
|
29
|
+
export const prime_field = p => {
|
|
30
30
|
/** @type {Reduce} */
|
|
31
31
|
const sub = a => b => {
|
|
32
32
|
const r = a - b
|
|
@@ -77,15 +77,12 @@ const prime_field = p => {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
return a
|
|
87
|
-
const result = pow(a)(sqrt_k)
|
|
88
|
-
return mul(result)(result) === a ? result : null
|
|
89
|
-
}
|
|
80
|
+
/** @type {(f: PrimeField) => (a: bigint) => bigint|null} */
|
|
81
|
+
export const sqrt = ({p, mul, pow }) => {
|
|
82
|
+
if ((p & 3n) !== 3n) { throw 'sqrt' }
|
|
83
|
+
const sqrt_k = (p + 1n) >> 2n
|
|
84
|
+
return a => {
|
|
85
|
+
const result = pow(a)(sqrt_k)
|
|
86
|
+
return mul(result)(result) === a ? result : null
|
|
90
87
|
}
|
|
91
88
|
}
|
package/prime_field/test.f.mjs
CHANGED
package/secp/module.f.d.mts
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
declare namespace _default {
|
|
2
|
-
export { curve };
|
|
3
|
-
export let eq: (a: Point) => (b: Point) => boolean;
|
|
4
|
-
export let secp256k1: Init;
|
|
5
|
-
export let secp192r1: Init;
|
|
6
|
-
}
|
|
7
|
-
export default _default;
|
|
8
|
-
export type Point2D = readonly [bigint, bigint];
|
|
9
|
-
export type Point = Point2D | null;
|
|
10
|
-
export type Init = {
|
|
11
|
-
readonly p: bigint;
|
|
12
|
-
readonly a: readonly [bigint, bigint];
|
|
13
|
-
readonly g: readonly [bigint, bigint];
|
|
14
|
-
readonly n: bigint;
|
|
15
|
-
};
|
|
16
|
-
export type Curve = {
|
|
17
|
-
readonly pf: Pf.PrimeField;
|
|
18
|
-
readonly nf: Pf.PrimeField;
|
|
19
|
-
readonly y2: (x: bigint) => bigint;
|
|
20
|
-
readonly y: (x: bigint) => bigint | null;
|
|
21
|
-
readonly neg: (a: Point) => Point;
|
|
22
|
-
readonly add: Operator.Reduce<Point>;
|
|
23
|
-
readonly mul: (a: Point) => (n: bigint) => Point;
|
|
24
|
-
};
|
|
25
1
|
/** @typedef {readonly[bigint, bigint]} Point2D */
|
|
26
2
|
/** @typedef {Point2D|null} Point */
|
|
27
3
|
/**
|
|
@@ -34,8 +10,8 @@ export type Curve = {
|
|
|
34
10
|
*/
|
|
35
11
|
/**
|
|
36
12
|
* @typedef {{
|
|
37
|
-
* readonly pf:
|
|
38
|
-
* readonly nf:
|
|
13
|
+
* readonly pf: pf.PrimeField
|
|
14
|
+
* readonly nf: pf.PrimeField
|
|
39
15
|
* readonly y2: (x: bigint) => bigint
|
|
40
16
|
* readonly y: (x: bigint) => bigint|null
|
|
41
17
|
* readonly neg: (a: Point) => Point
|
|
@@ -44,6 +20,29 @@ export type Curve = {
|
|
|
44
20
|
* }} Curve
|
|
45
21
|
*/
|
|
46
22
|
/** @type {(i: Init) => Curve} */
|
|
47
|
-
|
|
48
|
-
|
|
23
|
+
export const curve: (i: Init) => Curve;
|
|
24
|
+
/** @type {(a: Point) => (b: Point) => boolean} */
|
|
25
|
+
export const eq: (a: Point) => (b: Point) => boolean;
|
|
26
|
+
/** @type {Init} */
|
|
27
|
+
export const secp256k1: Init;
|
|
28
|
+
/** @type {Init} */
|
|
29
|
+
export const secp192r1: Init;
|
|
30
|
+
export type Point2D = readonly [bigint, bigint];
|
|
31
|
+
export type Point = Point2D | null;
|
|
32
|
+
export type Init = {
|
|
33
|
+
readonly p: bigint;
|
|
34
|
+
readonly a: readonly [bigint, bigint];
|
|
35
|
+
readonly g: readonly [bigint, bigint];
|
|
36
|
+
readonly n: bigint;
|
|
37
|
+
};
|
|
38
|
+
export type Curve = {
|
|
39
|
+
readonly pf: pf.PrimeField;
|
|
40
|
+
readonly nf: pf.PrimeField;
|
|
41
|
+
readonly y2: (x: bigint) => bigint;
|
|
42
|
+
readonly y: (x: bigint) => bigint | null;
|
|
43
|
+
readonly neg: (a: Point) => Point;
|
|
44
|
+
readonly add: Operator.Reduce<Point>;
|
|
45
|
+
readonly mul: (a: Point) => (n: bigint) => Point;
|
|
46
|
+
};
|
|
47
|
+
import * as pf from '../prime_field/module.f.mjs';
|
|
49
48
|
import * as Operator from '../types/function/operator/module.f.mjs';
|
package/secp/module.f.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-self-types="./module.f.d.mts"
|
|
2
2
|
import * as Operator from '../types/function/operator/module.f.mjs'
|
|
3
|
-
import
|
|
4
|
-
import bi from '../types/bigint/module.f.mjs'
|
|
3
|
+
import * as pf from '../prime_field/module.f.mjs'
|
|
4
|
+
import * as bi from '../types/bigint/module.f.mjs'
|
|
5
5
|
const { scalar_mul } = bi
|
|
6
6
|
const { prime_field, sqrt } = pf
|
|
7
7
|
|
|
@@ -20,8 +20,8 @@ const { prime_field, sqrt } = pf
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* @typedef {{
|
|
23
|
-
* readonly pf:
|
|
24
|
-
* readonly nf:
|
|
23
|
+
* readonly pf: pf.PrimeField
|
|
24
|
+
* readonly nf: pf.PrimeField
|
|
25
25
|
* readonly y2: (x: bigint) => bigint
|
|
26
26
|
* readonly y: (x: bigint) => bigint|null
|
|
27
27
|
* readonly neg: (a: Point) => Point
|
|
@@ -31,7 +31,7 @@ const { prime_field, sqrt } = pf
|
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
33
|
/** @type {(i: Init) => Curve} */
|
|
34
|
-
const curve = ({ p, a: [a0, a1], n }) => {
|
|
34
|
+
export const curve = ({ p, a: [a0, a1], n }) => {
|
|
35
35
|
const pf = prime_field(p)
|
|
36
36
|
const { pow2, pow3, sub, add, mul, neg, div } = pf
|
|
37
37
|
const mul3 = mul(3n)
|
|
@@ -85,38 +85,37 @@ const curve = ({ p, a: [a0, a1], n }) => {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
},
|
|
88
|
+
/** @type {(a: Point) => (b: Point) => boolean} */
|
|
89
|
+
export const eq = a => b => {
|
|
90
|
+
if (a === null || b === null) {
|
|
91
|
+
return a === b
|
|
92
|
+
}
|
|
93
|
+
const [ax, ay] = a
|
|
94
|
+
const [bx, by] = b
|
|
95
|
+
return ax === bx && ay === by
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** @type {Init} */
|
|
99
|
+
export const secp256k1 = {
|
|
100
|
+
p: 0xffffffff_ffffffff_ffffffff_ffffffff_ffffffff_ffffffff_fffffffe_fffffc2fn,
|
|
101
|
+
a: [7n, 0n],
|
|
102
|
+
g: [
|
|
103
|
+
0x79be667e_f9dcbbac_55a06295_ce870b07_029bfcdb_2dce28d9_59f2815b_16f81798n,
|
|
104
|
+
0x483ada77_26a3c465_5da4fbfc_0e1108a8_fd17b448_a6855419_9c47d08f_fb10d4b8n
|
|
105
|
+
],
|
|
106
|
+
n: 0xffffffff_ffffffff_ffffffff_fffffffe_baaedce6_af48a03b_bfd25e8c_d0364141n,
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** @type {Init} */
|
|
110
|
+
export const secp192r1 = {
|
|
111
|
+
p: 0xffffffff_ffffffff_ffffffff_fffffffe_ffffffff_ffffffffn,
|
|
112
|
+
a: [
|
|
113
|
+
0x64210519_e59c80e7_0fa7e9ab_72243049_feb8deec_c146b9b1n,
|
|
114
|
+
0xffffffff_ffffffff_ffffffff_fffffffe_ffffffff_fffffffcn
|
|
115
|
+
],
|
|
116
|
+
g: [
|
|
117
|
+
0x188da80e_b03090f6_7cbf20eb_43a18800_f4ff0afd_82ff1012n,
|
|
118
|
+
0x07192b95_ffc8da78_631011ed_6b24cdd5_73f977a1_1e794811n
|
|
119
|
+
],
|
|
120
|
+
n: 0xffffffff_ffffffff_ffffffff_99def836_146bc9b1_b4d22831n,
|
|
122
121
|
}
|
package/secp/test.f.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _ from './module.f.mjs'
|
|
2
2
|
const { curve, secp256k1, secp192r1, eq } = _
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
test: () => {
|
|
6
|
-
/** @type {(c:
|
|
6
|
+
/** @type {(c: _.Init) => void} */
|
|
7
7
|
const test_curve = c => {
|
|
8
8
|
const { g } = c
|
|
9
9
|
const { mul, neg, pf: { abs }, y: yf, nf: { p: n } } = curve(c)
|
|
10
|
-
/** @type {(p:
|
|
10
|
+
/** @type {(p: _.Point) => void} */
|
|
11
11
|
const point_check = p => {
|
|
12
12
|
if (p === null) { throw 'null' }
|
|
13
13
|
const [x, y] = p
|
|
@@ -17,7 +17,7 @@ export default {
|
|
|
17
17
|
}
|
|
18
18
|
point_check(g)
|
|
19
19
|
point_check(neg(g))
|
|
20
|
-
/** @type {(p:
|
|
20
|
+
/** @type {(p: _.Point) => void} */
|
|
21
21
|
const test_mul = p => {
|
|
22
22
|
if (mul(p)(0n) !== null) { throw 'O' }
|
|
23
23
|
if (mul(p)(1n) !== p) { throw 'p' }
|
package/sha2/module.f.d.mts
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
1
|
+
/** @type {(input: readonly number[]) => (bits: number) => HashInput} */
|
|
2
|
+
export const padding: (input: readonly number[]) => (bits: number) => HashInput;
|
|
3
|
+
/** @type {(input: readonly number[]) => (bitsCount: number) => Hash8} */
|
|
4
|
+
export const computeSha256: (input: readonly number[]) => (bitsCount: number) => Hash8;
|
|
5
|
+
/** @type {(input: readonly number[]) => (bitsCount: number) => Hash8} */
|
|
6
|
+
export const computeSha224: (input: readonly number[]) => (bitsCount: number) => Hash8;
|
|
7
|
+
export const compress256: (data: Array16) => Hash8;
|
|
8
|
+
export const compress224: (data: Array16) => Hash8;
|
|
9
9
|
export type HashInput = {
|
|
10
10
|
readonly f: (i: number) => number;
|
|
11
11
|
readonly length: number;
|
|
12
12
|
};
|
|
13
13
|
export type Hash8 = arrayT.Array8<number>;
|
|
14
14
|
export type Array16 = arrayT.Array16<number>;
|
|
15
|
-
/** @type {(input: readonly number[]) => (bits: number) => HashInput} */
|
|
16
|
-
declare const padding: (input: readonly number[]) => (bits: number) => HashInput;
|
|
17
|
-
/** @type {(input: readonly number[]) => (bitsCount: number) => Hash8} */
|
|
18
|
-
declare const computeSha256: (input: readonly number[]) => (bitsCount: number) => Hash8;
|
|
19
|
-
/** @type {(input: readonly number[]) => (bitsCount: number) => Hash8} */
|
|
20
|
-
declare const computeSha224: (input: readonly number[]) => (bitsCount: number) => Hash8;
|
|
21
|
-
declare const compress256: (data: Array16) => Hash8;
|
|
22
|
-
declare const compress224: (data: Array16) => Hash8;
|
|
23
15
|
import * as arrayT from '../types/array/module.f.mjs';
|
package/sha2/module.f.mjs
CHANGED
|
@@ -19,7 +19,7 @@ const appendOneWithZeros = input => pos => (input >> pos << pos) | (1 << pos)
|
|
|
19
19
|
const mod = a => b => (a % b + b) % b
|
|
20
20
|
|
|
21
21
|
/** @type {(input: readonly number[]) => (bits: number) => HashInput} */
|
|
22
|
-
const padding = input => bitsCount => {
|
|
22
|
+
export const padding = input => bitsCount => {
|
|
23
23
|
const appendBlockIndex = (bitsCount / 32) | 0
|
|
24
24
|
const length = (bitsCount + mod(447 - bitsCount)(512) + 65) / 32
|
|
25
25
|
/** @type {(i: number) => number} */
|
|
@@ -183,27 +183,14 @@ const compute = init => input => bitsCount => {
|
|
|
183
183
|
const init256 = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]
|
|
184
184
|
|
|
185
185
|
/** @type {(input: readonly number[]) => (bitsCount: number) => Hash8} */
|
|
186
|
-
const computeSha256 = compute(init256)
|
|
186
|
+
export const computeSha256 = compute(init256)
|
|
187
187
|
|
|
188
188
|
/** @type {Hash8} */
|
|
189
189
|
const init224 = [0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4]
|
|
190
190
|
|
|
191
191
|
/** @type {(input: readonly number[]) => (bitsCount: number) => Hash8} */
|
|
192
|
-
const computeSha224 = compute(init224)
|
|
193
|
-
|
|
194
|
-
const compress256 = compress(init256)
|
|
195
|
-
|
|
196
|
-
const compress224 = compress(init224)
|
|
197
|
-
|
|
198
|
-
export default {
|
|
199
|
-
/** @readonly */
|
|
200
|
-
padding,
|
|
201
|
-
/** @readonly */
|
|
202
|
-
computeSha256,
|
|
203
|
-
/** @readonly */
|
|
204
|
-
computeSha224,
|
|
205
|
-
/** @readonly */
|
|
206
|
-
compress256,
|
|
207
|
-
/** @readonly */
|
|
208
|
-
compress224
|
|
209
|
-
}
|
|
192
|
+
export const computeSha224 = compute(init224)
|
|
193
|
+
|
|
194
|
+
export const compress256 = compress(init256)
|
|
195
|
+
|
|
196
|
+
export const compress224 = compress(init224)
|
package/sha2/test.f.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import _ from './module.f.mjs'
|
|
2
|
-
import
|
|
3
|
-
import o from '../types/object/module.f.mjs'
|
|
1
|
+
import * as _ from './module.f.mjs'
|
|
2
|
+
import * as json from '../json/module.f.mjs'
|
|
3
|
+
import * as o from '../types/object/module.f.mjs'
|
|
4
4
|
const { sort } = o
|
|
5
5
|
|
|
6
6
|
/** @type {(a: number) => number} */
|
|
@@ -9,7 +9,7 @@ const toU32 = x => (x + 0x1_0000_0000) % 0x1_0000_0000
|
|
|
9
9
|
/** @type {(a: number) => string} */
|
|
10
10
|
const toHexString = x => toU32(x).toString(16).padStart(8, '0')
|
|
11
11
|
|
|
12
|
-
/** @type {(a: readonly
|
|
12
|
+
/** @type {(a: readonly json.Unknown[]) => string} */
|
|
13
13
|
const stringify = a => json.stringify(sort)(a)
|
|
14
14
|
|
|
15
15
|
// {
|