functionalscript 0.1.609 → 0.2.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.
- package/com/cpp/module.f.mjs +20 -25
- package/com/cpp/testlib.f.mjs +3 -4
- package/com/cs/module.f.mjs +18 -23
- package/com/cs/testlib.f.mjs +3 -5
- package/com/rust/module.f.mjs +25 -30
- package/com/rust/testlib.f.mjs +3 -5
- package/com/test/build.f.mjs +2 -2
- package/com/test/build.mjs +4 -4
- package/com/types/module.f.mjs +5 -12
- package/commonjs/build/module.f.mjs +23 -28
- package/commonjs/build/test.f.mjs +4 -4
- package/commonjs/module/function/module.f.mjs +0 -2
- package/commonjs/module/module.f.mjs +2 -9
- package/commonjs/module.f.mjs +0 -2
- package/commonjs/module.mjs +2 -7
- package/commonjs/package/dependencies/module.f.mjs +5 -10
- package/commonjs/package/dependencies/test.f.mjs +1 -1
- package/commonjs/package/module.f.mjs +6 -13
- package/commonjs/package/test.f.mjs +1 -1
- 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.mjs +1 -4
- package/dev/module.mjs +1 -1
- package/dev/test/module.f.mjs +4 -6
- package/djs/module.f.mjs +12 -19
- package/djs/parser/module.f.mjs +18 -24
- package/djs/parser/test.f.mjs +9 -9
- package/djs/test.f.mjs +4 -4
- package/djs/tokenizer/module.f.mjs +18 -23
- package/djs/tokenizer/test.f.mjs +6 -6
- package/fsc/module.f.mjs +17 -24
- package/fsc/test.f.mjs +3 -3
- package/fsm/module.f.mjs +27 -38
- package/fsm/test.f.mjs +8 -8
- package/html/module.f.mjs +14 -23
- package/html/test.f.mjs +4 -4
- package/js/tokenizer/module.f.mjs +55 -62
- package/js/tokenizer/test.f.mjs +6 -6
- package/json/module.f.mjs +18 -31
- package/json/parser/module.f.mjs +9 -14
- package/json/parser/test.f.mjs +7 -7
- 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.mjs +14 -19
- package/json/tokenizer/test.f.mjs +6 -6
- package/jsr.json +59 -59
- package/nodejs/version/main.mjs +1 -1
- package/nodejs/version/module.f.mjs +2 -7
- package/nodejs/version/test.f.mjs +3 -3
- package/out/com/cpp/module.f.d.mts +4 -0
- package/out/com/cpp/module.f.mjs +123 -0
- package/out/com/cpp/test.f.mjs +40 -0
- package/out/com/cpp/testlib.f.mjs +7 -0
- package/out/com/cs/module.f.d.mts +4 -0
- package/out/com/cs/module.f.mjs +95 -0
- package/out/com/cs/test.f.mjs +43 -0
- package/out/com/cs/testlib.f.mjs +7 -0
- package/{com → out/com}/rust/module.f.d.mts +3 -7
- package/out/com/rust/module.f.mjs +213 -0
- package/out/com/rust/test.f.mjs +123 -0
- package/out/com/rust/testlib.f.mjs +7 -0
- package/{com → out/com}/test/build.f.d.mts +2 -2
- package/out/com/test/build.f.mjs +98 -0
- package/out/com/test/build.mjs +40 -0
- package/{com → out/com}/types/module.f.d.mts +5 -10
- package/out/com/types/module.f.mjs +51 -0
- package/out/com/types/testlib.f.mjs +30 -0
- package/out/commonjs/build/module.f.d.mts +20 -0
- package/out/commonjs/build/module.f.mjs +107 -0
- package/out/commonjs/build/test.f.mjs +102 -0
- package/{commonjs → out/commonjs}/module/function/module.f.d.mts +0 -2
- package/out/commonjs/module/function/module.f.mjs +15 -0
- package/{commonjs → out/commonjs}/module/module.f.d.mts +16 -21
- package/out/commonjs/module/module.f.mjs +48 -0
- package/out/commonjs/module.d.mts +3 -0
- package/{commonjs → out/commonjs}/module.f.d.mts +0 -2
- package/out/commonjs/module.f.mjs +10 -0
- package/out/commonjs/module.mjs +26 -0
- package/out/commonjs/package/dependencies/module.f.d.mts +6 -0
- package/out/commonjs/package/dependencies/module.f.mjs +21 -0
- package/out/commonjs/package/dependencies/test.f.mjs +15 -0
- package/out/commonjs/package/module.f.d.mts +21 -0
- package/out/commonjs/package/module.f.mjs +40 -0
- package/out/commonjs/package/test.f.mjs +27 -0
- package/{commonjs → out/commonjs}/path/module.f.d.mts +25 -32
- package/out/commonjs/path/module.f.mjs +171 -0
- package/out/commonjs/path/test.f.mjs +231 -0
- package/out/commonjs/test.mjs +87 -0
- package/out/dev/index.mjs +2 -0
- package/out/dev/module.f.d.mts +1 -0
- package/out/dev/module.f.mjs +2 -0
- package/out/dev/module.mjs +167 -0
- package/{dev → out/dev}/test/module.f.d.mts +2 -3
- package/out/dev/test/module.f.mjs +134 -0
- package/out/dev/test.f.mjs +58 -0
- package/out/dev/test.mjs +52 -0
- package/{djs → out/djs}/module.f.d.mts +13 -18
- package/out/djs/module.f.mjs +75 -0
- package/{djs → out/djs}/parser/module.f.d.mts +11 -15
- package/out/djs/parser/module.f.mjs +432 -0
- package/out/djs/parser/test.f.mjs +535 -0
- package/out/djs/test.f.mjs +84 -0
- package/out/djs/tokenizer/module.f.d.mts +13 -0
- package/out/djs/tokenizer/module.f.mjs +87 -0
- package/out/djs/tokenizer/test.f.mjs +480 -0
- package/out/fsc/module.f.d.mts +7 -0
- package/out/fsc/module.f.mjs +105 -0
- package/out/fsc/test.f.mjs +19 -0
- package/out/fsm/module.f.d.mts +14 -0
- package/out/fsm/module.f.mjs +80 -0
- package/out/fsm/test.f.mjs +138 -0
- package/out/html/module.f.d.mts +15 -0
- package/out/html/module.f.mjs +94 -0
- package/out/html/test.f.mjs +45 -0
- package/out/issues/test.f.mjs +66 -0
- package/{js → out/js}/tokenizer/module.f.d.mts +10 -15
- package/out/js/tokenizer/module.f.mjs +686 -0
- package/out/js/tokenizer/test.f.mjs +844 -0
- package/out/json/module.f.d.mts +33 -0
- package/out/json/module.f.mjs +89 -0
- package/{json → out/json}/parser/module.f.d.mts +9 -13
- package/out/json/parser/module.f.mjs +224 -0
- package/out/json/parser/test.f.mjs +321 -0
- package/out/json/serializer/module.f.d.mts +36 -0
- package/out/json/serializer/module.f.mjs +67 -0
- package/out/json/serializer/test.f.mjs +87 -0
- package/out/json/test.f.mjs +61 -0
- package/out/json/tokenizer/module.f.d.mts +13 -0
- package/out/json/tokenizer/module.f.mjs +78 -0
- package/out/json/tokenizer/test.f.mjs +420 -0
- package/out/nanvm-lib/tests/test.f.mjs +87 -0
- package/out/nodejs/version/main.mjs +3 -0
- package/{nodejs → out/nodejs}/version/module.f.d.mts +4 -9
- package/out/nodejs/version/module.f.mjs +34 -0
- package/out/nodejs/version/test.f.mjs +97 -0
- package/{prime_field → out/prime_field}/module.f.d.mts +20 -23
- package/out/prime_field/module.f.mjs +87 -0
- package/out/prime_field/test.f.mjs +145 -0
- package/{secp → out/secp}/module.f.d.mts +27 -28
- package/out/secp/module.f.mjs +113 -0
- package/out/secp/test.f.mjs +63 -0
- package/out/sha2/module.f.d.mts +15 -0
- package/out/sha2/module.f.mjs +172 -0
- package/out/sha2/test.f.mjs +86 -0
- package/out/text/ascii/module.f.d.mts +70 -0
- package/out/text/ascii/module.f.mjs +154 -0
- package/out/text/ascii/test.f.mjs +14 -0
- package/out/text/module.f.d.mts +13 -0
- package/out/text/module.f.mjs +19 -0
- package/out/text/sgr/module.f.d.mts +12 -0
- package/out/text/sgr/module.f.mjs +17 -0
- package/out/text/test.f.mjs +19 -0
- package/out/text/utf16/module.f.d.mts +12 -0
- package/out/text/utf16/module.f.mjs +86 -0
- package/out/text/utf16/test.f.mjs +145 -0
- package/out/text/utf8/module.f.d.mts +10 -0
- package/out/text/utf8/module.f.mjs +126 -0
- package/out/text/utf8/test.f.mjs +175 -0
- package/{types → out/types}/array/module.f.d.mts +14 -24
- package/out/types/array/module.f.mjs +95 -0
- package/out/types/array/test.f.mjs +116 -0
- package/out/types/bigfloat/module.f.d.mts +6 -0
- package/out/types/bigfloat/module.f.mjs +77 -0
- package/out/types/bigfloat/test.f.mjs +349 -0
- package/out/types/bigint/module.f.d.mts +29 -0
- package/{types/bigint/module.f.d.mts → out/types/bigint/module.f.mjs} +64 -27
- package/out/types/bigint/test.f.mjs +192 -0
- package/{types → out/types}/btree/find/module.f.d.mts +20 -26
- package/out/types/btree/find/module.f.mjs +137 -0
- package/out/types/btree/find/test.f.mjs +156 -0
- package/out/types/btree/module.f.d.mts +5 -0
- package/out/types/btree/module.f.mjs +34 -0
- package/{types → out/types}/btree/remove/module.f.d.mts +7 -12
- package/out/types/btree/remove/module.f.mjs +209 -0
- package/out/types/btree/remove/test.f.mjs +638 -0
- package/{types → out/types}/btree/set/module.f.d.mts +3 -7
- package/out/types/btree/set/module.f.mjs +114 -0
- package/out/types/btree/set/test.f.mjs +390 -0
- package/out/types/btree/test.f.mjs +83 -0
- package/{types → out/types}/btree/types/module.f.d.mts +0 -2
- package/out/types/btree/types/module.f.mjs +50 -0
- package/out/types/byte_set/module.f.d.mts +25 -0
- package/out/types/byte_set/module.f.mjs +42 -0
- package/out/types/byte_set/test.f.mjs +123 -0
- package/{types → out/types}/function/compare/module.f.d.mts +9 -15
- package/out/types/function/compare/module.f.mjs +22 -0
- package/out/types/function/compare/test.f.mjs +8 -0
- package/{types → out/types}/function/module.f.d.mts +20 -27
- package/out/types/function/module.f.mjs +44 -0
- package/{types → out/types}/function/operator/module.f.d.mts +28 -43
- package/out/types/function/operator/module.f.mjs +60 -0
- package/out/types/function/test.f.mjs +15 -0
- package/out/types/list/module.f.d.mts +82 -0
- package/out/types/list/module.f.mjs +269 -0
- package/out/types/list/test.f.mjs +401 -0
- package/out/types/map/module.f.d.mts +21 -0
- package/out/types/map/module.f.mjs +54 -0
- package/out/types/map/test.f.mjs +115 -0
- package/out/types/nibble_set/module.f.d.mts +16 -0
- package/out/types/nibble_set/module.f.mjs +19 -0
- package/out/types/nibble_set/test.f.mjs +90 -0
- package/out/types/nullable/module.f.d.mts +9 -0
- package/out/types/nullable/module.f.mjs +9 -0
- package/out/types/nullable/test.f.mjs +12 -0
- package/out/types/number/module.f.d.mts +7 -0
- package/out/types/number/module.f.mjs +12 -0
- package/out/types/number/test.f.mjs +126 -0
- package/out/types/object/module.f.d.mts +22 -0
- package/out/types/object/module.f.mjs +27 -0
- package/out/types/object/test.f.mjs +17 -0
- package/out/types/range/module.f.d.mts +6 -0
- package/out/types/range/module.f.mjs +6 -0
- package/out/types/range/test.f.mjs +18 -0
- package/{types → out/types}/range_map/module.f.d.mts +9 -15
- package/out/types/range_map/module.f.mjs +84 -0
- package/out/types/range_map/test.f.mjs +201 -0
- package/out/types/result/module.d.mts +7 -0
- package/{types → out/types}/result/module.f.d.mts +6 -12
- package/out/types/result/module.f.mjs +25 -0
- package/out/types/result/module.mjs +16 -0
- package/{types → out/types}/sorted_list/module.f.d.mts +22 -28
- package/out/types/sorted_list/module.f.mjs +102 -0
- package/out/types/sorted_list/test.f.mjs +66 -0
- package/{types → out/types}/sorted_set/module.f.d.mts +6 -12
- package/out/types/sorted_set/module.f.mjs +29 -0
- package/out/types/sorted_set/test.f.mjs +80 -0
- package/out/types/string/module.f.d.mts +9 -0
- package/out/types/string/module.f.mjs +17 -0
- package/out/types/string/test.f.mjs +58 -0
- package/out/types/string_set/module.f.d.mts +13 -0
- package/out/types/string_set/module.f.mjs +29 -0
- package/out/types/string_set/test.f.mjs +65 -0
- package/package.json +5 -4
- package/prime_field/module.f.mjs +9 -12
- package/prime_field/test.f.mjs +1 -1
- package/secp/module.f.mjs +38 -39
- package/secp/test.f.mjs +4 -4
- package/sha2/module.f.mjs +7 -20
- package/sha2/test.f.mjs +4 -4
- package/text/ascii/module.f.mjs +5 -10
- package/text/ascii/test.f.mjs +3 -3
- package/text/module.f.mjs +7 -14
- package/text/sgr/module.f.mjs +2 -4
- package/text/test.f.mjs +3 -3
- package/text/utf16/module.f.mjs +17 -28
- package/text/utf16/test.f.mjs +5 -5
- package/text/utf8/module.f.mjs +9 -16
- package/text/utf8/test.f.mjs +4 -4
- package/tsconfig.json +2 -2
- package/types/array/module.f.mjs +8 -25
- package/types/array/test.f.mjs +3 -3
- package/types/bigfloat/module.f.mjs +3 -10
- package/types/bigfloat/test.f.mjs +1 -1
- package/types/bigint/module.f.mjs +11 -30
- package/types/bigint/test.f.mjs +1 -1
- package/types/btree/find/module.f.mjs +8 -17
- package/types/btree/find/test.f.mjs +7 -7
- package/types/btree/module.f.mjs +6 -11
- package/types/btree/remove/module.f.mjs +10 -17
- package/types/btree/remove/test.f.mjs +5 -5
- 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.mjs +0 -2
- package/types/byte_set/module.f.mjs +14 -39
- package/types/byte_set/test.f.mjs +5 -5
- package/types/function/compare/module.f.mjs +3 -12
- package/types/function/compare/test.f.mjs +1 -1
- package/types/function/module.f.mjs +4 -15
- package/types/function/operator/module.f.mjs +14 -41
- package/types/function/test.f.mjs +1 -1
- package/types/list/module.f.mjs +45 -114
- package/types/list/test.f.mjs +10 -10
- package/types/map/module.f.mjs +15 -30
- package/types/map/test.f.mjs +2 -2
- package/types/nibble_set/module.f.mjs +7 -24
- package/types/nibble_set/test.f.mjs +2 -2
- package/types/nullable/module.f.mjs +2 -9
- package/types/nullable/test.f.mjs +1 -1
- package/types/number/module.f.mjs +8 -19
- package/types/number/test.f.mjs +1 -1
- package/types/object/module.f.mjs +9 -20
- package/types/object/test.f.mjs +1 -1
- package/types/range/module.f.mjs +2 -9
- package/types/range/test.f.mjs +1 -1
- package/types/range_map/module.f.mjs +9 -18
- package/types/range_map/test.f.mjs +32 -32
- package/types/result/module.f.mjs +3 -12
- package/types/result/module.mjs +2 -2
- package/types/sorted_list/module.f.mjs +10 -19
- package/types/sorted_list/test.f.mjs +7 -7
- package/types/sorted_set/module.f.mjs +7 -16
- package/types/sorted_set/test.f.mjs +7 -7
- package/types/string/module.f.mjs +10 -21
- package/types/string/test.f.mjs +2 -2
- package/types/string_set/module.f.mjs +12 -27
- package/types/string_set/test.f.mjs +1 -1
- package/com/cpp/module.f.d.mts +0 -8
- package/com/cs/module.f.d.mts +0 -8
- package/commonjs/build/module.f.d.mts +0 -24
- package/commonjs/module.d.mts +0 -7
- package/commonjs/package/dependencies/module.f.d.mts +0 -10
- package/commonjs/package/module.f.d.mts +0 -27
- package/dev/module.f.d.mts +0 -4
- package/djs/tokenizer/module.f.d.mts +0 -17
- package/fsc/module.f.d.mts +0 -12
- package/fsm/module.f.d.mts +0 -21
- package/html/module.f.d.mts +0 -20
- package/json/module.f.d.mts +0 -41
- package/json/serializer/module.f.d.mts +0 -45
- package/json/tokenizer/module.f.d.mts +0 -17
- package/sha2/module.f.d.mts +0 -23
- package/text/ascii/module.f.d.mts +0 -73
- package/text/module.f.d.mts +0 -18
- package/text/sgr/module.f.d.mts +0 -14
- package/text/utf16/module.f.d.mts +0 -19
- package/text/utf8/module.f.d.mts +0 -15
- package/types/bigfloat/module.f.d.mts +0 -11
- package/types/btree/module.f.d.mts +0 -9
- package/types/byte_set/module.f.d.mts +0 -38
- package/types/list/module.f.d.mts +0 -117
- package/types/map/module.f.d.mts +0 -30
- package/types/nibble_set/module.f.d.mts +0 -26
- package/types/nullable/module.f.d.mts +0 -14
- package/types/number/module.f.d.mts +0 -13
- package/types/object/module.f.d.mts +0 -29
- package/types/range/module.f.d.mts +0 -11
- package/types/result/module.d.mts +0 -7
- package/types/string/module.f.d.mts +0 -15
- package/types/string_set/module.f.d.mts +0 -21
- /package/{com → out/com}/cpp/test.f.d.mts +0 -0
- /package/{com → out/com}/cpp/testlib.f.d.mts +0 -0
- /package/{com → out/com}/cs/test.f.d.mts +0 -0
- /package/{com → out/com}/cs/testlib.f.d.mts +0 -0
- /package/{com → out/com}/rust/test.f.d.mts +0 -0
- /package/{com → out/com}/rust/testlib.f.d.mts +0 -0
- /package/{com → out/com}/test/build.d.mts +0 -0
- /package/{com → out/com}/types/testlib.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/build/test.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/package/dependencies/test.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/package/test.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/path/test.f.d.mts +0 -0
- /package/{commonjs → out/commonjs}/test.d.mts +0 -0
- /package/{dev → out/dev}/index.d.mts +0 -0
- /package/{dev → out/dev}/module.d.mts +0 -0
- /package/{dev → out/dev}/test.d.mts +0 -0
- /package/{dev → out/dev}/test.f.d.mts +0 -0
- /package/{djs → out/djs}/parser/test.f.d.mts +0 -0
- /package/{djs → out/djs}/test.f.d.mts +0 -0
- /package/{djs → out/djs}/tokenizer/test.f.d.mts +0 -0
- /package/{fsc → out/fsc}/test.f.d.mts +0 -0
- /package/{fsm → out/fsm}/test.f.d.mts +0 -0
- /package/{html → out/html}/test.f.d.mts +0 -0
- /package/{issues → out/issues}/test.f.d.mts +0 -0
- /package/{js → out/js}/tokenizer/test.f.d.mts +0 -0
- /package/{json → out/json}/parser/test.f.d.mts +0 -0
- /package/{json → out/json}/serializer/test.f.d.mts +0 -0
- /package/{json → out/json}/test.f.d.mts +0 -0
- /package/{json → out/json}/tokenizer/test.f.d.mts +0 -0
- /package/{nanvm-lib → out/nanvm-lib}/tests/test.f.d.mts +0 -0
- /package/{nodejs → out/nodejs}/version/main.d.mts +0 -0
- /package/{nodejs → out/nodejs}/version/test.f.d.mts +0 -0
- /package/{prime_field → out/prime_field}/test.f.d.mts +0 -0
- /package/{secp → out/secp}/test.f.d.mts +0 -0
- /package/{sha2 → out/sha2}/test.f.d.mts +0 -0
- /package/{text → out/text}/ascii/test.f.d.mts +0 -0
- /package/{text → out/text}/test.f.d.mts +0 -0
- /package/{text → out/text}/utf16/test.f.d.mts +0 -0
- /package/{text → out/text}/utf8/test.f.d.mts +0 -0
- /package/{types → out/types}/array/test.f.d.mts +0 -0
- /package/{types → out/types}/bigfloat/test.f.d.mts +0 -0
- /package/{types → out/types}/bigint/test.f.d.mts +0 -0
- /package/{types → out/types}/btree/find/test.f.d.mts +0 -0
- /package/{types → out/types}/btree/remove/test.f.d.mts +0 -0
- /package/{types → out/types}/btree/set/test.f.d.mts +0 -0
- /package/{types → out/types}/btree/test.f.d.mts +0 -0
- /package/{types → out/types}/byte_set/test.f.d.mts +0 -0
- /package/{types → out/types}/function/compare/test.f.d.mts +0 -0
- /package/{types → out/types}/function/test.f.d.mts +0 -0
- /package/{types → out/types}/list/test.f.d.mts +0 -0
- /package/{types → out/types}/map/test.f.d.mts +0 -0
- /package/{types → out/types}/nibble_set/test.f.d.mts +0 -0
- /package/{types → out/types}/nullable/test.f.d.mts +0 -0
- /package/{types → out/types}/number/test.f.d.mts +0 -0
- /package/{types → out/types}/object/test.f.d.mts +0 -0
- /package/{types → out/types}/range/test.f.d.mts +0 -0
- /package/{types → out/types}/range_map/test.f.d.mts +0 -0
- /package/{types → out/types}/sorted_list/test.f.d.mts +0 -0
- /package/{types → out/types}/sorted_set/test.f.d.mts +0 -0
- /package/{types → out/types}/string/test.f.d.mts +0 -0
- /package/{types → out/types}/string_set/test.f.d.mts +0 -0
|
@@ -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';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// @ts-self-types="./module.f.d.mts"
|
|
2
|
+
import * as Operator from '../types/function/operator/module.f.mjs';
|
|
3
|
+
import * as bi from '../types/bigint/module.f.mjs';
|
|
4
|
+
const { scalar_mul } = bi;
|
|
5
|
+
/** @typedef {Operator.Reduce<bigint>} Reduce */
|
|
6
|
+
/** @typedef {Operator.Unary<bigint, bigint>} Unary*/
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {{
|
|
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
|
+
* }} PrimeField
|
|
23
|
+
*/
|
|
24
|
+
/** @type {(p: bigint) => PrimeField} */
|
|
25
|
+
export const prime_field = p => {
|
|
26
|
+
/** @type {Reduce} */
|
|
27
|
+
const sub = a => b => {
|
|
28
|
+
const r = a - b;
|
|
29
|
+
return r < 0 ? r + p : r;
|
|
30
|
+
};
|
|
31
|
+
/** @type {Reduce} */
|
|
32
|
+
const mul = a => b => a * b % p;
|
|
33
|
+
/** @type {Unary} */
|
|
34
|
+
const reciprocal = a => {
|
|
35
|
+
if (a === 0n) {
|
|
36
|
+
throw '1/0';
|
|
37
|
+
}
|
|
38
|
+
let a1 = a;
|
|
39
|
+
let a0 = p;
|
|
40
|
+
let f0 = 0n;
|
|
41
|
+
let f1 = 1n;
|
|
42
|
+
while (a1 !== 1n) {
|
|
43
|
+
const q = a0 / a1;
|
|
44
|
+
const a2 = a0 % a1;
|
|
45
|
+
a0 = a1;
|
|
46
|
+
a1 = a2;
|
|
47
|
+
const f2 = sub(f0)(mul(f1)(q));
|
|
48
|
+
f0 = f1;
|
|
49
|
+
f1 = f2;
|
|
50
|
+
}
|
|
51
|
+
return f1;
|
|
52
|
+
};
|
|
53
|
+
const middle = p >> 1n;
|
|
54
|
+
/** @type {Unary} */
|
|
55
|
+
const pow2 = a => mul(a)(a);
|
|
56
|
+
/** @type {Reduce} */
|
|
57
|
+
const pow = scalar_mul({ 0: 1n, add: mul });
|
|
58
|
+
return {
|
|
59
|
+
p,
|
|
60
|
+
middle,
|
|
61
|
+
max: p - 1n,
|
|
62
|
+
neg: a => a === 0n ? 0n : p - a,
|
|
63
|
+
sub,
|
|
64
|
+
add: a => b => {
|
|
65
|
+
const r = a + b;
|
|
66
|
+
return r < p ? r : r - p;
|
|
67
|
+
},
|
|
68
|
+
abs: a => middle < a ? p - a : a,
|
|
69
|
+
mul,
|
|
70
|
+
reciprocal,
|
|
71
|
+
div: a => b => mul(a)(reciprocal(b)),
|
|
72
|
+
pow,
|
|
73
|
+
pow2,
|
|
74
|
+
pow3: a => mul(a)(pow2(a))
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
/** @type {(f: PrimeField) => (a: bigint) => bigint|null} */
|
|
78
|
+
export const sqrt = ({ p, mul, pow }) => {
|
|
79
|
+
if ((p & 3n) !== 3n) {
|
|
80
|
+
throw 'sqrt';
|
|
81
|
+
}
|
|
82
|
+
const sqrt_k = (p + 1n) >> 2n;
|
|
83
|
+
return a => {
|
|
84
|
+
const result = pow(a)(sqrt_k);
|
|
85
|
+
return mul(result)(result) === a ? result : null;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import * as _ from './module.f.mjs';
|
|
2
|
+
const { prime_field, sqrt } = _;
|
|
3
|
+
export default {
|
|
4
|
+
prime_field_test: () => {
|
|
5
|
+
const p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn;
|
|
6
|
+
const f = prime_field(p);
|
|
7
|
+
const sqrt_f = sqrt(f);
|
|
8
|
+
return {
|
|
9
|
+
neg: () => {
|
|
10
|
+
if (f.neg(0n) !== 0n) {
|
|
11
|
+
throw '-0';
|
|
12
|
+
}
|
|
13
|
+
if (f.neg(1n) !== p - 1n) {
|
|
14
|
+
throw '-1';
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
sub: () => {
|
|
18
|
+
if (f.sub(10n)(4n) !== 6n) {
|
|
19
|
+
throw '10 - 4';
|
|
20
|
+
}
|
|
21
|
+
if (f.sub(11n)(14n) !== p - 3n) {
|
|
22
|
+
throw '11 - 14';
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
add: () => {
|
|
26
|
+
if (f.add(13n)(24n) !== 37n) {
|
|
27
|
+
throw '13 + 24';
|
|
28
|
+
}
|
|
29
|
+
if (f.add(77n)(f.neg(12n)) !== 65n) {
|
|
30
|
+
throw '77 + (-12)';
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
mul: () => {
|
|
34
|
+
if (f.mul(100n)(0n) !== 0n) {
|
|
35
|
+
throw '100 * 0';
|
|
36
|
+
}
|
|
37
|
+
if (f.mul(101n)(205n) !== 20705n) {
|
|
38
|
+
throw '101 * 205';
|
|
39
|
+
}
|
|
40
|
+
if (f.mul(304n)(f.neg(1n)) !== f.neg(304n)) {
|
|
41
|
+
throw '304 * -1';
|
|
42
|
+
}
|
|
43
|
+
if (f.mul(f.neg(507n))(609n) !== f.neg(308763n)) {
|
|
44
|
+
throw '-507 * 609';
|
|
45
|
+
}
|
|
46
|
+
if (f.mul(f.neg(713n))(f.neg(825n)) !== 588225n) {
|
|
47
|
+
throw '-713 * -825';
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
reciprocal: () => {
|
|
51
|
+
let i = 1n;
|
|
52
|
+
while (i < 10000n) {
|
|
53
|
+
const x = f.reciprocal(i);
|
|
54
|
+
if (f.mul(x)(i) !== 1n) {
|
|
55
|
+
throw i;
|
|
56
|
+
}
|
|
57
|
+
++i;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
pow: () => {
|
|
61
|
+
/** @type {(a: bigint) => void} */
|
|
62
|
+
const test = a => {
|
|
63
|
+
if (f.pow(a)(0n) !== 1n) {
|
|
64
|
+
throw '**0';
|
|
65
|
+
}
|
|
66
|
+
if (f.pow(a)(1n) !== a) {
|
|
67
|
+
throw '**1';
|
|
68
|
+
}
|
|
69
|
+
// https://en.wikipedia.org/wiki/Fermat%27s_little_theorem
|
|
70
|
+
// a^(p-1) % p = 1
|
|
71
|
+
if (f.abs(f.pow(a)(f.middle)) !== 1n) {
|
|
72
|
+
throw '**middle';
|
|
73
|
+
}
|
|
74
|
+
if (f.pow(a)(f.sub(f.max)(1n)) !== f.reciprocal(a)) {
|
|
75
|
+
throw '**(max-1)';
|
|
76
|
+
}
|
|
77
|
+
if (f.pow(a)(f.max) !== 1n) {
|
|
78
|
+
throw '**max';
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
// 0
|
|
82
|
+
if (f.pow(0n)(0n) !== 1n) {
|
|
83
|
+
throw '0**0';
|
|
84
|
+
}
|
|
85
|
+
if (f.pow(0n)(f.max) !== 0n) {
|
|
86
|
+
throw '0**max';
|
|
87
|
+
}
|
|
88
|
+
// 1
|
|
89
|
+
test(1n);
|
|
90
|
+
// 2
|
|
91
|
+
test(2n);
|
|
92
|
+
if (f.pow(2n)(2n) !== 4n) {
|
|
93
|
+
throw '2**2';
|
|
94
|
+
}
|
|
95
|
+
if (f.pow(2n)(3n) !== 8n) {
|
|
96
|
+
throw '2**3';
|
|
97
|
+
}
|
|
98
|
+
if (f.pow(2n)(128n) !== 1n << 128n) {
|
|
99
|
+
throw '2**128';
|
|
100
|
+
}
|
|
101
|
+
// 3
|
|
102
|
+
test(3n);
|
|
103
|
+
if (f.pow(3n)(2n) !== 9n) {
|
|
104
|
+
throw '3**2';
|
|
105
|
+
}
|
|
106
|
+
if (f.pow(3n)(3n) !== 27n) {
|
|
107
|
+
throw '3**3';
|
|
108
|
+
}
|
|
109
|
+
if (f.pow(3n)(100n) !== 3n ** 100n) {
|
|
110
|
+
throw '3**100';
|
|
111
|
+
}
|
|
112
|
+
if (f.pow(3n)(110n) !== 3n ** 110n) {
|
|
113
|
+
throw '3**110';
|
|
114
|
+
}
|
|
115
|
+
if (f.pow(3n)(120n) !== 3n ** 120n) {
|
|
116
|
+
throw '3**120';
|
|
117
|
+
}
|
|
118
|
+
if (f.pow(3n)(121n) !== 3n ** 121n) {
|
|
119
|
+
throw '3**121';
|
|
120
|
+
}
|
|
121
|
+
//
|
|
122
|
+
test(f.middle);
|
|
123
|
+
test(f.max - 1n);
|
|
124
|
+
test(f.max);
|
|
125
|
+
},
|
|
126
|
+
sqrt: () => {
|
|
127
|
+
/** @type {(a: bigint) => void} */
|
|
128
|
+
const test = a => {
|
|
129
|
+
const a2 = f.mul(a)(a);
|
|
130
|
+
const s = sqrt_f(a2);
|
|
131
|
+
if (s !== null && f.abs(s) !== f.abs(a)) {
|
|
132
|
+
throw 'sqrt';
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
let i = 1n;
|
|
136
|
+
while (i < 1000n) {
|
|
137
|
+
test(i);
|
|
138
|
+
++i;
|
|
139
|
+
}
|
|
140
|
+
test(f.middle);
|
|
141
|
+
test(f.max);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
};
|
|
@@ -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';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// @ts-self-types="./module.f.d.mts"
|
|
2
|
+
import * as Operator from '../types/function/operator/module.f.mjs';
|
|
3
|
+
import * as pf from '../prime_field/module.f.mjs';
|
|
4
|
+
import * as bi from '../types/bigint/module.f.mjs';
|
|
5
|
+
const { scalar_mul } = bi;
|
|
6
|
+
const { prime_field, sqrt } = pf;
|
|
7
|
+
/** @typedef {readonly[bigint, bigint]} Point2D */
|
|
8
|
+
/** @typedef {Point2D|null} Point */
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {{
|
|
11
|
+
* readonly p: bigint
|
|
12
|
+
* readonly a: readonly[bigint, bigint]
|
|
13
|
+
* readonly g: readonly[bigint, bigint]
|
|
14
|
+
* readonly n: bigint
|
|
15
|
+
* }} Init
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {{
|
|
19
|
+
* readonly pf: pf.PrimeField
|
|
20
|
+
* readonly nf: pf.PrimeField
|
|
21
|
+
* readonly y2: (x: bigint) => bigint
|
|
22
|
+
* readonly y: (x: bigint) => bigint|null
|
|
23
|
+
* readonly neg: (a: Point) => Point
|
|
24
|
+
* readonly add: Operator.Reduce<Point>
|
|
25
|
+
* readonly mul: (a: Point) => (n: bigint) => Point
|
|
26
|
+
* }} Curve
|
|
27
|
+
*/
|
|
28
|
+
/** @type {(i: Init) => Curve} */
|
|
29
|
+
export const curve = ({ p, a: [a0, a1], n }) => {
|
|
30
|
+
const pf = prime_field(p);
|
|
31
|
+
const { pow2, pow3, sub, add, mul, neg, div } = pf;
|
|
32
|
+
const mul3 = mul(3n);
|
|
33
|
+
const mul2 = mul(2n);
|
|
34
|
+
const addA1 = add(a1);
|
|
35
|
+
const mulA1 = mul(a1);
|
|
36
|
+
const addA0 = add(a0);
|
|
37
|
+
// y**2 = a1*x**3 + a0
|
|
38
|
+
/** @type {(x: bigint) => bigint} */
|
|
39
|
+
const y2 = x => addA0(add(pow3(x))(mulA1(x)));
|
|
40
|
+
/** @type {Operator.Reduce<Point>} */
|
|
41
|
+
const addPoint = p => q => {
|
|
42
|
+
if (p === null) {
|
|
43
|
+
return q;
|
|
44
|
+
}
|
|
45
|
+
if (q === null) {
|
|
46
|
+
return p;
|
|
47
|
+
}
|
|
48
|
+
const [px, py] = p;
|
|
49
|
+
const [qx, qy] = q;
|
|
50
|
+
const md = px === qx
|
|
51
|
+
// (3 * px ** 2 + a1) / (2 * py)
|
|
52
|
+
? py !== qy || py === 0n ? null : [addA1(mul3(pow2(px))), mul2(py)]
|
|
53
|
+
// (py - qy) / (px - qx)
|
|
54
|
+
: [sub(py)(qy), sub(px)(qx)];
|
|
55
|
+
if (md === null) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const [ma, mb] = md;
|
|
59
|
+
const m = div(ma)(mb);
|
|
60
|
+
// m ** 2 - px - qx
|
|
61
|
+
const rx = sub(pow2(m))(add(px)(qx));
|
|
62
|
+
// [rx, m * (px - rx) - py]
|
|
63
|
+
return [rx, sub(mul(m)(sub(px)(rx)))(py)];
|
|
64
|
+
};
|
|
65
|
+
const sqrt_p = sqrt(pf);
|
|
66
|
+
return {
|
|
67
|
+
pf,
|
|
68
|
+
nf: prime_field(n),
|
|
69
|
+
y2,
|
|
70
|
+
y: x => sqrt_p(y2(x)),
|
|
71
|
+
neg: p => {
|
|
72
|
+
if (p === null) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const [x, y] = p;
|
|
76
|
+
return [x, neg(y)];
|
|
77
|
+
},
|
|
78
|
+
add: addPoint,
|
|
79
|
+
mul: scalar_mul({ 0: null, add: addPoint })
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
/** @type {(a: Point) => (b: Point) => boolean} */
|
|
83
|
+
export const eq = a => b => {
|
|
84
|
+
if (a === null || b === null) {
|
|
85
|
+
return a === b;
|
|
86
|
+
}
|
|
87
|
+
const [ax, ay] = a;
|
|
88
|
+
const [bx, by] = b;
|
|
89
|
+
return ax === bx && ay === by;
|
|
90
|
+
};
|
|
91
|
+
/** @type {Init} */
|
|
92
|
+
export const secp256k1 = {
|
|
93
|
+
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,
|
|
94
|
+
a: [7n, 0n],
|
|
95
|
+
g: [
|
|
96
|
+
0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,
|
|
97
|
+
0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n
|
|
98
|
+
],
|
|
99
|
+
n: 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,
|
|
100
|
+
};
|
|
101
|
+
/** @type {Init} */
|
|
102
|
+
export const secp192r1 = {
|
|
103
|
+
p: 0xfffffffffffffffffffffffffffffffeffffffffffffffffn,
|
|
104
|
+
a: [
|
|
105
|
+
0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1n,
|
|
106
|
+
0xfffffffffffffffffffffffffffffffefffffffffffffffcn
|
|
107
|
+
],
|
|
108
|
+
g: [
|
|
109
|
+
0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012n,
|
|
110
|
+
0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811n
|
|
111
|
+
],
|
|
112
|
+
n: 0xffffffffffffffffffffffff99def836146bc9b1b4d22831n,
|
|
113
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as _ from './module.f.mjs';
|
|
2
|
+
const { curve, secp256k1, secp192r1, eq } = _;
|
|
3
|
+
export default {
|
|
4
|
+
test: () => {
|
|
5
|
+
/** @type {(c: _.Init) => void} */
|
|
6
|
+
const test_curve = c => {
|
|
7
|
+
const { g } = c;
|
|
8
|
+
const { mul, neg, pf: { abs }, y: yf, nf: { p: n } } = curve(c);
|
|
9
|
+
/** @type {(p: _.Point) => void} */
|
|
10
|
+
const point_check = p => {
|
|
11
|
+
if (p === null) {
|
|
12
|
+
throw 'null';
|
|
13
|
+
}
|
|
14
|
+
const [x, y] = p;
|
|
15
|
+
const ye = yf(x);
|
|
16
|
+
if (ye === null) {
|
|
17
|
+
throw 'null';
|
|
18
|
+
}
|
|
19
|
+
if (abs(ye) !== abs(y)) {
|
|
20
|
+
throw 'ye';
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
point_check(g);
|
|
24
|
+
point_check(neg(g));
|
|
25
|
+
/** @type {(p: _.Point) => void} */
|
|
26
|
+
const test_mul = p => {
|
|
27
|
+
if (mul(p)(0n) !== null) {
|
|
28
|
+
throw 'O';
|
|
29
|
+
}
|
|
30
|
+
if (mul(p)(1n) !== p) {
|
|
31
|
+
throw 'p';
|
|
32
|
+
}
|
|
33
|
+
if (mul(p)(n) !== null) {
|
|
34
|
+
throw 'n';
|
|
35
|
+
}
|
|
36
|
+
const pn = neg(p);
|
|
37
|
+
if (!eq(mul(p)(n - 1n))(pn)) {
|
|
38
|
+
throw 'n - 1';
|
|
39
|
+
}
|
|
40
|
+
/** @type {(s: bigint) => void} */
|
|
41
|
+
const f = s => {
|
|
42
|
+
const r = mul(p)(s);
|
|
43
|
+
point_check(r);
|
|
44
|
+
const rn = mul(pn)(s);
|
|
45
|
+
point_check(rn);
|
|
46
|
+
if (!eq(r)(neg(rn))) {
|
|
47
|
+
throw 'r != -rn';
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
f(2n);
|
|
51
|
+
f(3n);
|
|
52
|
+
f(4n << 128n);
|
|
53
|
+
f((5n << 128n) + 6n);
|
|
54
|
+
f(7n << 128n);
|
|
55
|
+
f((8n << 128n) + 9n);
|
|
56
|
+
};
|
|
57
|
+
test_mul(g);
|
|
58
|
+
test_mul(neg(g));
|
|
59
|
+
};
|
|
60
|
+
test_curve(secp256k1);
|
|
61
|
+
test_curve(secp192r1);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
export type HashInput = {
|
|
10
|
+
readonly f: (i: number) => number;
|
|
11
|
+
readonly length: number;
|
|
12
|
+
};
|
|
13
|
+
export type Hash8 = arrayT.Array8<number>;
|
|
14
|
+
export type Array16 = arrayT.Array16<number>;
|
|
15
|
+
import * as arrayT from '../types/array/module.f.mjs';
|