functionalscript 0.3.3 → 0.3.5
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.d.ts +10 -0
- package/com/cpp/module.f.js +107 -0
- package/com/cpp/test.f.d.ts +2 -0
- package/com/cpp/{test.f.ts → test.f.js} +9 -11
- package/com/cpp/testlib.f.d.ts +2 -0
- package/com/cpp/testlib.f.js +5 -0
- package/com/cs/module.f.d.ts +12 -0
- package/com/cs/module.f.js +80 -0
- package/com/cs/test.f.d.ts +2 -0
- package/com/cs/{test.f.ts → test.f.js} +9 -11
- package/com/cs/testlib.f.d.ts +2 -0
- package/com/cs/testlib.f.js +5 -0
- package/com/rust/module.f.d.ts +15 -0
- package/com/rust/module.f.js +169 -0
- package/com/rust/test.f.d.ts +2 -0
- package/com/rust/{test.f.ts → test.f.js} +7 -7
- package/com/rust/testlib.f.d.ts +2 -0
- package/com/rust/testlib.f.js +5 -0
- package/com/test/build.f.d.ts +20 -0
- package/com/test/build.f.js +58 -0
- package/com/types/module.f.d.ts +28 -0
- package/com/types/module.f.js +8 -0
- package/com/types/testlib.f.d.ts +44 -0
- package/com/types/{testlib.f.ts → testlib.f.js} +2 -3
- package/commonjs/build/module.f.d.ts +6 -0
- package/commonjs/build/module.f.js +69 -0
- package/commonjs/build/test.f.d.ts +2 -0
- package/commonjs/build/test.f.js +96 -0
- package/commonjs/module/function/{module.f.ts → module.f.d.ts} +5 -10
- package/commonjs/module/function/module.f.js +4 -0
- package/commonjs/module/module.f.d.ts +18 -0
- package/commonjs/module/module.f.js +12 -0
- package/commonjs/module.f.d.ts +6 -0
- package/commonjs/module.f.js +1 -0
- package/commonjs/package/dependencies/module.f.d.ts +7 -0
- package/commonjs/package/dependencies/module.f.js +13 -0
- package/commonjs/package/dependencies/test.f.d.ts +2 -0
- package/commonjs/package/dependencies/test.f.js +15 -0
- package/commonjs/package/module.f.d.ts +17 -0
- package/commonjs/package/module.f.js +18 -0
- package/commonjs/package/test.f.d.ts +2 -0
- package/commonjs/package/test.f.js +27 -0
- package/commonjs/path/module.f.d.ts +24 -0
- package/commonjs/path/module.f.js +114 -0
- package/commonjs/path/test.f.d.ts +25 -0
- package/commonjs/path/{test.f.ts → test.f.js} +123 -89
- package/crypto/prime_field/module.f.d.ts +43 -0
- package/crypto/prime_field/module.f.js +78 -0
- package/crypto/prime_field/test.f.d.ts +13 -0
- package/crypto/prime_field/test.f.js +149 -0
- package/crypto/secp/module.f.d.ts +68 -0
- package/crypto/secp/module.f.js +127 -0
- package/crypto/secp/test.f.d.ts +5 -0
- package/crypto/secp/test.f.js +72 -0
- package/crypto/sha2/module.f.d.ts +13 -0
- package/crypto/sha2/module.f.js +145 -0
- package/crypto/sha2/test.f.d.ts +9 -0
- package/crypto/sha2/test.f.js +82 -0
- package/dev/module.f.d.ts +1 -0
- package/dev/module.f.js +1 -0
- package/dev/test/module.f.d.ts +20 -0
- package/dev/test/module.f.js +75 -0
- package/dev/test.f.d.ts +9 -0
- package/dev/{test.f.ts → test.f.js} +22 -24
- package/djs/module.f.d.ts +17 -0
- package/djs/module.f.js +63 -0
- package/djs/parser/module.f.d.ts +12 -0
- package/djs/parser/module.f.js +333 -0
- package/djs/parser/test.f.d.ts +12 -0
- package/djs/parser/test.f.js +717 -0
- package/djs/serializer/module.f.d.ts +9 -0
- package/djs/serializer/module.f.js +81 -0
- package/djs/test/input.f.d.ts +2 -0
- package/djs/test/input.f.js +4 -0
- package/djs/test/m.f.d.ts +2 -0
- package/djs/test/m.f.js +1 -0
- package/djs/test.f.d.ts +12 -0
- package/djs/test.f.js +84 -0
- package/djs/tokenizer/module.f.d.ts +8 -0
- package/djs/tokenizer/module.f.js +60 -0
- package/djs/tokenizer/test.f.d.ts +7 -0
- package/djs/tokenizer/test.f.js +529 -0
- package/fsc/module.f.d.ts +5 -0
- package/fsc/module.f.js +75 -0
- package/fsc/test.f.d.ts +4 -0
- package/fsc/test.f.js +19 -0
- package/fsm/module.f.d.ts +13 -0
- package/fsm/module.f.js +59 -0
- package/fsm/test.f.d.ts +5 -0
- package/fsm/test.f.js +137 -0
- package/html/module.f.d.ts +13 -0
- package/html/module.f.js +58 -0
- package/html/test.f.d.ts +9 -0
- package/html/test.f.js +42 -0
- package/issues/test.f.d.ts +16 -0
- package/issues/test.f.js +70 -0
- package/js/tokenizer/module.f.d.ts +86 -0
- package/js/tokenizer/module.f.js +503 -0
- package/js/tokenizer/test.f.d.ts +9 -0
- package/js/tokenizer/test.f.js +905 -0
- package/json/module.f.d.ts +20 -0
- package/json/module.f.js +68 -0
- package/json/parser/module.f.d.ts +5 -0
- package/json/parser/module.f.js +155 -0
- package/json/parser/test.f.d.ts +5 -0
- package/json/parser/test.f.js +328 -0
- package/json/serializer/module.f.d.ts +7 -0
- package/json/serializer/module.f.js +21 -0
- package/json/serializer/test.f.d.ts +8 -0
- package/json/serializer/test.f.js +87 -0
- package/json/test.f.d.ts +8 -0
- package/json/test.f.js +61 -0
- package/json/tokenizer/module.f.d.ts +8 -0
- package/json/tokenizer/module.f.js +52 -0
- package/json/tokenizer/test.f.d.ts +6 -0
- package/json/tokenizer/test.f.js +419 -0
- package/nanvm-lib/tests/test.f.d.ts +27 -0
- package/nanvm-lib/tests/test.f.js +84 -0
- package/nodejs/version/module.f.d.ts +11 -0
- package/nodejs/version/module.f.js +16 -0
- package/nodejs/version/test.f.d.ts +2 -0
- package/nodejs/version/{test.f.ts → test.f.js} +13 -22
- package/package.json +9 -5
- package/text/ascii/module.f.d.ts +129 -0
- package/text/ascii/module.f.js +148 -0
- package/text/ascii/test.f.d.ts +4 -0
- package/text/ascii/test.f.js +14 -0
- package/text/module.f.d.ts +8 -0
- package/text/module.f.js +10 -0
- package/text/sgr/module.f.d.ts +8 -0
- package/text/sgr/module.f.js +8 -0
- package/text/test.f.d.ts +2 -0
- package/text/test.f.js +18 -0
- package/text/utf16/module.f.d.ts +9 -0
- package/text/utf16/module.f.js +66 -0
- package/text/utf16/test.f.d.ts +6 -0
- package/text/utf16/test.f.js +144 -0
- package/text/utf8/module.f.d.ts +6 -0
- package/text/utf8/module.f.js +112 -0
- package/text/utf8/test.f.d.ts +6 -0
- package/text/utf8/test.f.js +175 -0
- package/types/array/module.f.d.ts +21 -0
- package/types/array/module.f.js +23 -0
- package/types/array/test.f.d.ts +10 -0
- package/types/array/test.f.js +116 -0
- package/types/bigfloat/module.f.d.ts +3 -0
- package/types/bigfloat/module.f.js +66 -0
- package/types/bigfloat/test.f.d.ts +6 -0
- package/types/bigfloat/test.f.js +349 -0
- package/types/bigint/module.f.d.ts +54 -0
- package/types/bigint/{module.f.ts → module.f.js} +42 -65
- package/types/bigint/test.f.d.ts +16 -0
- package/types/bigint/test.f.js +199 -0
- package/types/bit_vec/module.f.d.ts +134 -0
- package/types/bit_vec/{module.f.ts → module.f.js} +47 -65
- package/types/bit_vec/test.f.d.ts +22 -0
- package/types/bit_vec/test.f.js +210 -0
- package/types/btree/find/module.f.d.ts +20 -0
- package/types/btree/find/module.f.js +84 -0
- package/types/btree/find/test.f.d.ts +2 -0
- package/types/btree/find/test.f.js +152 -0
- package/types/btree/module.f.d.ts +4 -0
- package/types/btree/module.f.js +31 -0
- package/types/btree/remove/module.f.d.ts +4 -0
- package/types/btree/remove/module.f.js +174 -0
- package/types/btree/remove/test.f.d.ts +5 -0
- package/types/btree/remove/test.f.js +634 -0
- package/types/btree/set/module.f.d.ts +3 -0
- package/types/btree/set/module.f.js +103 -0
- package/types/btree/set/test.f.d.ts +2 -0
- package/types/btree/set/test.f.js +360 -0
- package/types/btree/test.f.d.ts +8 -0
- package/types/btree/test.f.js +75 -0
- package/types/btree/types/module.f.d.ts +11 -0
- package/types/btree/types/module.f.js +1 -0
- package/types/byte_set/module.f.d.ts +16 -0
- package/types/byte_set/module.f.js +28 -0
- package/types/byte_set/test.f.d.ts +12 -0
- package/types/byte_set/test.f.js +122 -0
- package/types/function/compare/module.f.d.ts +10 -0
- package/types/function/compare/module.f.js +7 -0
- package/types/function/compare/test.f.d.ts +2 -0
- package/types/function/compare/test.f.js +8 -0
- package/types/function/module.f.d.ts +28 -0
- package/types/function/module.f.js +19 -0
- package/types/function/operator/module.f.d.ts +20 -0
- package/types/function/operator/module.f.js +18 -0
- package/types/function/test.f.d.ts +2 -0
- package/types/function/test.f.js +12 -0
- package/types/list/module.f.d.ts +50 -0
- package/types/list/module.f.js +171 -0
- package/types/list/test.f.d.ts +22 -0
- package/types/list/test.f.js +395 -0
- package/types/map/module.f.d.ts +14 -0
- package/types/map/module.f.js +31 -0
- package/types/map/test.f.d.ts +5 -0
- package/types/map/test.f.js +114 -0
- package/types/nibble_set/module.f.d.ts +10 -0
- package/types/nibble_set/module.f.js +9 -0
- package/types/nibble_set/test.f.d.ts +12 -0
- package/types/nibble_set/test.f.js +90 -0
- package/types/nullable/module.f.d.ts +3 -0
- package/types/nullable/module.f.js +2 -0
- package/types/nullable/test.f.d.ts +2 -0
- package/types/nullable/test.f.js +12 -0
- package/types/number/module.f.d.ts +6 -0
- package/types/number/module.f.js +8 -0
- package/types/number/test.f.d.ts +11 -0
- package/types/number/test.f.js +124 -0
- package/types/object/module.f.d.ts +10 -0
- package/types/object/module.f.js +12 -0
- package/types/object/test.f.d.ts +5 -0
- package/types/object/test.f.js +17 -0
- package/types/range/module.f.d.ts +3 -0
- package/types/range/module.f.js +2 -0
- package/types/range/test.f.d.ts +2 -0
- package/types/range/test.f.js +18 -0
- package/types/range_map/module.f.d.ts +14 -0
- package/types/range_map/module.f.js +51 -0
- package/types/range_map/test.f.d.ts +6 -0
- package/types/range_map/test.f.js +176 -0
- package/types/result/module.f.d.ts +7 -0
- package/types/result/module.f.js +8 -0
- package/types/sorted_list/module.f.d.ts +16 -0
- package/types/sorted_list/module.f.js +56 -0
- package/types/sorted_list/test.f.d.ts +5 -0
- package/types/sorted_list/test.f.js +64 -0
- package/types/sorted_set/module.f.d.ts +7 -0
- package/types/sorted_set/module.f.js +14 -0
- package/types/sorted_set/test.f.d.ts +6 -0
- package/types/sorted_set/test.f.js +78 -0
- package/types/string/module.f.d.ts +6 -0
- package/types/string/module.f.js +11 -0
- package/types/string/test.f.d.ts +15 -0
- package/types/string/test.f.js +58 -0
- package/types/string_set/module.f.d.ts +9 -0
- package/types/string_set/module.f.js +22 -0
- package/types/string_set/test.f.d.ts +5 -0
- package/types/string_set/test.f.js +65 -0
- package/.github/FUNDING.yml +0 -12
- package/.github/dependabot.yml +0 -11
- package/.github/workflows/ci.yml +0 -88
- package/.github/workflows/npm-publish.yml +0 -53
- package/CHANGELOG.md +0 -29
- package/Cargo.lock +0 -18
- package/Cargo.toml +0 -7
- package/com/README.md +0 -3
- package/com/cpp/README.md +0 -80
- package/com/cpp/module.f.ts +0 -180
- package/com/cpp/nanocom.hpp +0 -195
- package/com/cpp/testlib.f.ts +0 -8
- package/com/cs/module.f.ts +0 -145
- package/com/cs/testlib.f.ts +0 -8
- package/com/proposals.md +0 -28
- package/com/rust/module.f.ts +0 -287
- package/com/rust/nanocom/Cargo.lock +0 -7
- package/com/rust/nanocom/Cargo.toml +0 -15
- package/com/rust/nanocom/README.md +0 -56
- package/com/rust/nanocom/src/class.rs +0 -6
- package/com/rust/nanocom/src/cobject.rs +0 -90
- package/com/rust/nanocom/src/guid.rs +0 -15
- package/com/rust/nanocom/src/hresult.rs +0 -7
- package/com/rust/nanocom/src/interface.rs +0 -9
- package/com/rust/nanocom/src/iunknown.rs +0 -13
- package/com/rust/nanocom/src/lib.rs +0 -20
- package/com/rust/nanocom/src/object.rs +0 -34
- package/com/rust/nanocom/src/ref.rs +0 -57
- package/com/rust/nanocom/src/vmt.rs +0 -7
- package/com/rust/nanocom/tests/it.rs +0 -186
- package/com/rust/nanocom/tests/itmod.rs +0 -195
- package/com/rust/testlib.f.ts +0 -8
- package/com/test/build.f.ts +0 -111
- package/com/test/build.ts +0 -45
- package/com/test/cpp/main.cpp +0 -74
- package/com/test/cs/Program.cs +0 -31
- package/com/test/cs/cs.csproj +0 -16
- package/com/test/rust/Cargo.toml +0 -12
- package/com/test/rust/src/lib.rs +0 -56
- package/com/types/module.f.ts +0 -62
- package/commonjs/README.md +0 -94
- package/commonjs/build/module.f.ts +0 -100
- package/commonjs/build/test.f.ts +0 -107
- package/commonjs/module/module.f.ts +0 -41
- package/commonjs/module.f.ts +0 -7
- package/commonjs/module.ts +0 -31
- package/commonjs/package/dependencies/module.f.ts +0 -22
- package/commonjs/package/dependencies/test.f.ts +0 -8
- package/commonjs/package/module.f.ts +0 -31
- package/commonjs/package/test.f.ts +0 -12
- package/commonjs/path/README.md +0 -17
- package/commonjs/path/module.f.ts +0 -171
- package/commonjs/test.ts +0 -64
- package/crypto/README.md +0 -3
- package/crypto/prime_field/module.f.ts +0 -114
- package/crypto/prime_field/test.f.ts +0 -95
- package/crypto/secp/module.f.ts +0 -182
- package/crypto/secp/test.f.ts +0 -68
- package/crypto/sha2/module.f.ts +0 -215
- package/crypto/sha2/test.f.ts +0 -83
- package/deno.json +0 -71
- package/dev/README.md +0 -8
- package/dev/index.ts +0 -3
- package/dev/module.f.ts +0 -1
- package/dev/module.ts +0 -196
- package/dev/test/module.f.ts +0 -135
- package/dev/test.ts +0 -53
- package/djs/README.md +0 -54
- package/djs/module.f.ts +0 -76
- package/djs/parser/module.f.ts +0 -509
- package/djs/parser/test.f.ts +0 -461
- package/djs/serializer/module.f.ts +0 -90
- package/djs/test.f.ts +0 -67
- package/djs/tokenizer/module.f.ts +0 -99
- package/djs/tokenizer/test.f.ts +0 -364
- package/doc/LANGUAGE.md +0 -255
- package/doc/README.md +0 -61
- package/doc/byte-code.md +0 -59
- package/doc/fa.md +0 -174
- package/doc/predefined.md +0 -143
- package/doc/proposals.md +0 -21
- package/doc/vm/README.md +0 -24
- package/doc/vm-rearchitecture.md +0 -129
- package/doc/vm.md +0 -150
- package/fsc/README.md +0 -111
- package/fsc/module.f.ts +0 -122
- package/fsc/test.f.ts +0 -21
- package/fsm/README.md +0 -113
- package/fsm/module.f.ts +0 -107
- package/fsm/test.f.ts +0 -139
- package/funding.json +0 -61
- package/html/README.md +0 -32
- package/html/module.f.ts +0 -109
- package/html/test.f.ts +0 -37
- package/issues/01-test-debug.md +0 -3
- package/issues/02-esm.md +0 -8
- package/issues/03-djs.md +0 -57
- package/issues/05-publish.md +0 -40
- package/issues/11-fs-load.md +0 -13
- package/issues/17-djs-extension.md +0 -6
- package/issues/README.md +0 -42
- package/issues/lang/1000-json.md +0 -50
- package/issues/lang/2110-default-export.md +0 -11
- package/issues/lang/2120-const.md +0 -14
- package/issues/lang/2130-default-import.md +0 -10
- package/issues/lang/2210-block-comment.md +0 -12
- package/issues/lang/2220-namespace-import.md +0 -25
- package/issues/lang/2310-undefined.md +0 -7
- package/issues/lang/2320-bigint.md +0 -7
- package/issues/lang/2330-property-accessor.md +0 -225
- package/issues/lang/2340-operators.md +0 -41
- package/issues/lang/2350-grouping.md +0 -11
- package/issues/lang/2360-built-in.md +0 -81
- package/issues/lang/2410-identifier-property.md +0 -9
- package/issues/lang/2420-line-comment.md +0 -10
- package/issues/lang/2430-trailing-comma.md +0 -13
- package/issues/lang/2440-shorthand.md +0 -8
- package/issues/lang/2450-destructuring.md +0 -12
- package/issues/lang/3110-function.md +0 -35
- package/issues/lang/3120-parameters.md +0 -9
- package/issues/lang/3130-body-const.md +0 -12
- package/issues/lang/3220-let.md +0 -11
- package/issues/lang/3240-export.md +0 -44
- package/issues/lang/3370-type-inference.md +0 -69
- package/issues/lang/3380-promise.md +0 -22
- package/issues/lang/3390-class.md +0 -3
- package/issues/lang/3410-expression.md +0 -12
- package/issues/lang/3420-one-parameter.md +0 -10
- package/issues/lang/3430-assignments.md +0 -23
- package/issues/lang/README.md +0 -193
- package/issues/test.f.ts +0 -58
- package/js/tokenizer/module.f.ts +0 -882
- package/js/tokenizer/test.f.ts +0 -617
- package/json/html/README.md +0 -49
- package/json/module.f.ts +0 -94
- package/json/parser/module.f.ts +0 -221
- package/json/parser/test.f.ts +0 -255
- package/json/serializer/module.f.ts +0 -74
- package/json/serializer/test.f.ts +0 -64
- package/json/test.f.ts +0 -48
- package/json/tokenizer/module.f.ts +0 -85
- package/json/tokenizer/test.f.ts +0 -290
- package/nanvm-lib/Cargo.toml +0 -6
- package/nanvm-lib/src/extension.rs +0 -130
- package/nanvm-lib/src/interface.rs +0 -133
- package/nanvm-lib/src/lib.rs +0 -7
- package/nanvm-lib/src/naive.rs +0 -236
- package/nanvm-lib/src/nanenum.rs +0 -236
- package/nanvm-lib/src/nullish.rs +0 -7
- package/nanvm-lib/src/sign.rs +0 -5
- package/nanvm-lib/src/simple.rs +0 -32
- package/nanvm-lib/tests/test.f.ts +0 -80
- package/nanvm-lib/tests/test.rs +0 -108
- package/nodejs/version/main.ts +0 -4
- package/nodejs/version/module.f.ts +0 -42
- package/text/README.md +0 -110
- package/text/ascii/module.f.ts +0 -222
- package/text/ascii/test.f.ts +0 -14
- package/text/module.f.ts +0 -30
- package/text/sgr/README.md +0 -3
- package/text/sgr/module.f.ts +0 -13
- package/text/test.f.ts +0 -19
- package/text/utf16/module.f.ts +0 -120
- package/text/utf16/test.f.ts +0 -107
- package/text/utf8/module.f.ts +0 -116
- package/text/utf8/test.f.ts +0 -125
- package/tsconfig.json +0 -104
- package/types/array/module.f.ts +0 -89
- package/types/array/test.f.ts +0 -88
- package/types/bigfloat/module.f.ts +0 -93
- package/types/bigfloat/test.f.ts +0 -218
- package/types/bigint/README.md +0 -35
- package/types/bigint/test.f.ts +0 -144
- package/types/bit_vec/README.md +0 -18
- package/types/bit_vec/test.f.ts +0 -129
- package/types/btree/README.md +0 -160
- package/types/btree/find/module.f.ts +0 -92
- package/types/btree/find/test.f.ts +0 -122
- package/types/btree/module.f.ts +0 -35
- package/types/btree/remove/module.f.ts +0 -151
- package/types/btree/remove/test.f.ts +0 -498
- package/types/btree/set/module.f.ts +0 -89
- package/types/btree/set/test.f.ts +0 -415
- package/types/btree/test.f.ts +0 -92
- package/types/btree/types/module.f.ts +0 -27
- package/types/byte_set/module.f.ts +0 -73
- package/types/byte_set/test.f.ts +0 -84
- package/types/function/compare/module.f.ts +0 -26
- package/types/function/compare/test.f.ts +0 -7
- package/types/function/module.f.ts +0 -43
- package/types/function/operator/module.f.ts +0 -65
- package/types/function/test.f.ts +0 -20
- package/types/list/module.f.ts +0 -350
- package/types/list/test.f.ts +0 -327
- package/types/map/module.f.ts +0 -65
- package/types/map/test.f.ts +0 -76
- package/types/nibble_set/module.f.ts +0 -34
- package/types/nibble_set/test.f.ts +0 -57
- package/types/nullable/module.f.ts +0 -9
- package/types/nullable/test.f.ts +0 -9
- package/types/number/module.f.ts +0 -20
- package/types/number/test.f.ts +0 -194
- package/types/object/module.f.ts +0 -30
- package/types/object/test.f.ts +0 -14
- package/types/range/module.f.ts +0 -10
- package/types/range/test.f.ts +0 -9
- package/types/range_map/module.f.ts +0 -70
- package/types/range_map/test.f.ts +0 -189
- package/types/result/module.f.ts +0 -20
- package/types/result/module.ts +0 -18
- package/types/sorted_list/module.f.ts +0 -83
- package/types/sorted_list/test.f.ts +0 -57
- package/types/sorted_set/module.f.ts +0 -36
- package/types/sorted_set/test.f.ts +0 -67
- package/types/string/module.f.ts +0 -26
- package/types/string/test.f.ts +0 -43
- package/types/string_set/module.f.ts +0 -37
- package/types/string_set/test.f.ts +0 -34
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as Operator from "../../types/function/operator/module.f.js";
|
|
2
|
+
import { prime_field, sqrt } from "../prime_field/module.f.js";
|
|
3
|
+
import { scalar_mul } from "../../types/bigint/module.f.js";
|
|
4
|
+
/**
|
|
5
|
+
* Constructs an elliptic curve with the given initialization parameters.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```js
|
|
10
|
+
* const curveParams = {
|
|
11
|
+
* p: 23n,
|
|
12
|
+
* a: [0n, 1n],
|
|
13
|
+
* g: [1n, 1n],
|
|
14
|
+
* n: 19n
|
|
15
|
+
* };
|
|
16
|
+
* const curveInstance = curve(curveParams);
|
|
17
|
+
*
|
|
18
|
+
* // Access curve operations
|
|
19
|
+
* const point = curveInstance.add([1n, 1n])([2n, 5n]); // Add two points
|
|
20
|
+
* const negPoint = curveInstance.neg([1n, 1n]); // Negate a point
|
|
21
|
+
* const mulPoint = curveInstance.mul([1n, 1n])(3n); // Multiply a point by 3
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export const curve = ({ p, a: [a0, a1], n }) => {
|
|
25
|
+
const pf = prime_field(p);
|
|
26
|
+
const { pow2, pow3, sub, add, mul, neg, div } = pf;
|
|
27
|
+
const mul3 = mul(3n);
|
|
28
|
+
const mul2 = mul(2n);
|
|
29
|
+
const addA1 = add(a1);
|
|
30
|
+
const mulA1 = mul(a1);
|
|
31
|
+
const addA0 = add(a0);
|
|
32
|
+
/**
|
|
33
|
+
* y**2 = a1*x**3 + a0
|
|
34
|
+
*/
|
|
35
|
+
const y2 = x => addA0(add(pow3(x))(mulA1(x)));
|
|
36
|
+
const addPoint = p => q => {
|
|
37
|
+
if (p === null) {
|
|
38
|
+
return q;
|
|
39
|
+
}
|
|
40
|
+
if (q === null) {
|
|
41
|
+
return p;
|
|
42
|
+
}
|
|
43
|
+
const [px, py] = p;
|
|
44
|
+
const [qx, qy] = q;
|
|
45
|
+
const md = px === qx
|
|
46
|
+
// (3 * px ** 2 + a1) / (2 * py)
|
|
47
|
+
? py !== qy || py === 0n ? null : [addA1(mul3(pow2(px))), mul2(py)]
|
|
48
|
+
// (py - qy) / (px - qx)
|
|
49
|
+
: [sub(py)(qy), sub(px)(qx)];
|
|
50
|
+
if (md === null) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const [ma, mb] = md;
|
|
54
|
+
const m = div(ma)(mb);
|
|
55
|
+
// m ** 2 - px - qx
|
|
56
|
+
const rx = sub(pow2(m))(add(px)(qx));
|
|
57
|
+
// [rx, m * (px - rx) - py]
|
|
58
|
+
return [rx, sub(mul(m)(sub(px)(rx)))(py)];
|
|
59
|
+
};
|
|
60
|
+
const sqrt_p = sqrt(pf);
|
|
61
|
+
return {
|
|
62
|
+
pf,
|
|
63
|
+
nf: prime_field(n),
|
|
64
|
+
y2,
|
|
65
|
+
y: x => sqrt_p(y2(x)),
|
|
66
|
+
neg: p => {
|
|
67
|
+
if (p === null) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const [x, y] = p;
|
|
71
|
+
return [x, neg(y)];
|
|
72
|
+
},
|
|
73
|
+
add: addPoint,
|
|
74
|
+
mul: scalar_mul({ 0: null, add: addPoint })
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export const eq = a => b => {
|
|
78
|
+
if (a === null || b === null) {
|
|
79
|
+
return a === b;
|
|
80
|
+
}
|
|
81
|
+
const [ax, ay] = a;
|
|
82
|
+
const [bx, by] = b;
|
|
83
|
+
return ax === bx && ay === by;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* https://neuromancer.sk/std/secg/secp192r1
|
|
87
|
+
*/
|
|
88
|
+
export const secp192r1 = {
|
|
89
|
+
p: 0xfffffffffffffffffffffffffffffffeffffffffffffffffn,
|
|
90
|
+
a: [
|
|
91
|
+
0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1n,
|
|
92
|
+
0xfffffffffffffffffffffffffffffffefffffffffffffffcn
|
|
93
|
+
],
|
|
94
|
+
g: [
|
|
95
|
+
0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012n,
|
|
96
|
+
0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811n
|
|
97
|
+
],
|
|
98
|
+
n: 0xffffffffffffffffffffffff99def836146bc9b1b4d22831n,
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* https://en.bitcoin.it/wiki/Secp256k1
|
|
102
|
+
* https://neuromancer.sk/std/secg/secp256k1
|
|
103
|
+
*/
|
|
104
|
+
export const secp256k1 = {
|
|
105
|
+
p: 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,
|
|
106
|
+
a: [7n, 0n],
|
|
107
|
+
g: [
|
|
108
|
+
0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,
|
|
109
|
+
0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n
|
|
110
|
+
],
|
|
111
|
+
n: 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* https://neuromancer.sk/std/secg/secp256r1
|
|
115
|
+
*/
|
|
116
|
+
export const secp256r1 = {
|
|
117
|
+
p: 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffffn,
|
|
118
|
+
a: [
|
|
119
|
+
0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604bn, //< b
|
|
120
|
+
0xffffffff00000001000000000000000000000000fffffffffffffffffffffffcn, //< a
|
|
121
|
+
],
|
|
122
|
+
g: [
|
|
123
|
+
0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296n, //< x
|
|
124
|
+
0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5n, //< y
|
|
125
|
+
],
|
|
126
|
+
n: 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551n,
|
|
127
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { curve, secp256k1, secp192r1, secp256r1, eq } from "./module.f.js";
|
|
2
|
+
export default {
|
|
3
|
+
example: () => {
|
|
4
|
+
const curveParams = {
|
|
5
|
+
p: 23n,
|
|
6
|
+
a: [0n, 1n],
|
|
7
|
+
g: [1n, 1n],
|
|
8
|
+
n: 19n
|
|
9
|
+
};
|
|
10
|
+
const c = curve(curveParams);
|
|
11
|
+
// Access curve operations
|
|
12
|
+
const point = c.add([1n, 1n])([2n, 5n]); // Add two points
|
|
13
|
+
const negPoint = c.neg([1n, 1n]); // Negate a point
|
|
14
|
+
const mulPoint = c.mul([1n, 1n])(3n); // Multiply a point by 3
|
|
15
|
+
},
|
|
16
|
+
test: () => {
|
|
17
|
+
const test_curve = c => {
|
|
18
|
+
const { g } = c;
|
|
19
|
+
const { mul, neg, pf: { abs }, y: yf, nf: { p: n } } = curve(c);
|
|
20
|
+
const point_check = p => {
|
|
21
|
+
if (p === null) {
|
|
22
|
+
throw 'p === null';
|
|
23
|
+
}
|
|
24
|
+
const [x, y] = p;
|
|
25
|
+
const ye = yf(x);
|
|
26
|
+
if (ye === null) {
|
|
27
|
+
throw 'ye === null';
|
|
28
|
+
}
|
|
29
|
+
if (abs(ye) !== abs(y)) {
|
|
30
|
+
throw 'ye';
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
point_check(g);
|
|
34
|
+
point_check(neg(g));
|
|
35
|
+
const test_mul = p => {
|
|
36
|
+
if (mul(p)(0n) !== null) {
|
|
37
|
+
throw 'O';
|
|
38
|
+
}
|
|
39
|
+
if (mul(p)(1n) !== p) {
|
|
40
|
+
throw 'p';
|
|
41
|
+
}
|
|
42
|
+
if (mul(p)(n) !== null) {
|
|
43
|
+
throw 'n';
|
|
44
|
+
}
|
|
45
|
+
const pn = neg(p);
|
|
46
|
+
if (!eq(mul(p)(n - 1n))(pn)) {
|
|
47
|
+
throw 'n - 1';
|
|
48
|
+
}
|
|
49
|
+
const f = s => {
|
|
50
|
+
const r = mul(p)(s);
|
|
51
|
+
point_check(r);
|
|
52
|
+
const rn = mul(pn)(s);
|
|
53
|
+
point_check(rn);
|
|
54
|
+
if (!eq(r)(neg(rn))) {
|
|
55
|
+
throw 'r != -rn';
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
f(2n);
|
|
59
|
+
f(3n);
|
|
60
|
+
f(4n << 128n);
|
|
61
|
+
f((5n << 128n) + 6n);
|
|
62
|
+
f(7n << 128n);
|
|
63
|
+
f((8n << 128n) + 9n);
|
|
64
|
+
};
|
|
65
|
+
test_mul(g);
|
|
66
|
+
test_mul(neg(g));
|
|
67
|
+
};
|
|
68
|
+
test_curve(secp256k1);
|
|
69
|
+
test_curve(secp192r1);
|
|
70
|
+
test_curve(secp256r1);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as array from '../../types/array/module.f.ts';
|
|
2
|
+
type HashInput = {
|
|
3
|
+
readonly f: (i: number) => number;
|
|
4
|
+
readonly length: number;
|
|
5
|
+
};
|
|
6
|
+
type Hash8 = array.Array8<number>;
|
|
7
|
+
type Array16 = array.Array16<number>;
|
|
8
|
+
export declare const padding: (input: readonly number[]) => (bits: number) => HashInput;
|
|
9
|
+
export declare const computeSha256: (input: readonly number[]) => (bitsCount: number) => Hash8;
|
|
10
|
+
export declare const computeSha224: (input: readonly number[]) => (bitsCount: number) => Hash8;
|
|
11
|
+
export declare const compress256: (data: Array16) => Hash8;
|
|
12
|
+
export declare const compress224: (data: Array16) => Hash8;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import * as array from "../../types/array/module.f.js";
|
|
2
|
+
const appendOneWithZeros = input => pos => (input >> pos << pos) | (1 << pos);
|
|
3
|
+
const mod = a => b => (a % b + b) % b;
|
|
4
|
+
export const padding = input => bitsCount => {
|
|
5
|
+
const appendBlockIndex = (bitsCount / 32) | 0;
|
|
6
|
+
const length = (bitsCount + mod(447 - bitsCount)(512) + 65) / 32;
|
|
7
|
+
const f = i => {
|
|
8
|
+
if (i < appendBlockIndex) {
|
|
9
|
+
return input[i];
|
|
10
|
+
}
|
|
11
|
+
if (i === appendBlockIndex) {
|
|
12
|
+
return appendBlockIndex >= input.length ? 0x8000_0000 : appendOneWithZeros(input[appendBlockIndex])(31 - bitsCount % 32);
|
|
13
|
+
}
|
|
14
|
+
if (i === length - 2) {
|
|
15
|
+
return (bitsCount / 0x1_0000_0000) | 0;
|
|
16
|
+
}
|
|
17
|
+
if (i === length - 1) {
|
|
18
|
+
return bitsCount % 0x1_0000_0000;
|
|
19
|
+
}
|
|
20
|
+
return 0;
|
|
21
|
+
};
|
|
22
|
+
return ({ f, length });
|
|
23
|
+
};
|
|
24
|
+
const rotr = d => {
|
|
25
|
+
const r = 32 - d;
|
|
26
|
+
return n => n >>> d | n << r;
|
|
27
|
+
};
|
|
28
|
+
const ch = x => y => z => x & y ^ ~x & z;
|
|
29
|
+
const maj = x => y => z => x & y ^ x & z ^ y & z;
|
|
30
|
+
const shr = d => n => n >>> d;
|
|
31
|
+
const bigSigma = a => b => c => {
|
|
32
|
+
const ra = rotr(a);
|
|
33
|
+
const rb = rotr(b);
|
|
34
|
+
const rc = rotr(c);
|
|
35
|
+
return x => ra(x) ^ rb(x) ^ rc(x);
|
|
36
|
+
};
|
|
37
|
+
const bigSigma0 = bigSigma(2)(13)(22);
|
|
38
|
+
const bigSigma1 = bigSigma(6)(11)(25);
|
|
39
|
+
const smallSigma = a => b => c => {
|
|
40
|
+
const ra = rotr(a);
|
|
41
|
+
const rb = rotr(b);
|
|
42
|
+
const sc = shr(c);
|
|
43
|
+
return x => ra(x) ^ rb(x) ^ sc(x);
|
|
44
|
+
};
|
|
45
|
+
const smallSigma0 = smallSigma(7)(18)(3);
|
|
46
|
+
const smallSigma1 = smallSigma(17)(19)(10);
|
|
47
|
+
const wi = ([a0, a1, a2, a3]) => (smallSigma1(a0) + a1 + smallSigma0(a2) + a3) | 0;
|
|
48
|
+
const nextW = ([w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, wA, wB, wC, wD, wE, wF]) => {
|
|
49
|
+
w0 = wi([wE, w9, w1, w0]);
|
|
50
|
+
w1 = wi([wF, wA, w2, w1]);
|
|
51
|
+
w2 = wi([w0, wB, w3, w2]);
|
|
52
|
+
w3 = wi([w1, wC, w4, w3]);
|
|
53
|
+
w4 = wi([w2, wD, w5, w4]);
|
|
54
|
+
w5 = wi([w3, wE, w6, w5]);
|
|
55
|
+
w6 = wi([w4, wF, w7, w6]);
|
|
56
|
+
w7 = wi([w5, w0, w8, w7]);
|
|
57
|
+
w8 = wi([w6, w1, w9, w8]);
|
|
58
|
+
w9 = wi([w7, w2, wA, w9]);
|
|
59
|
+
wA = wi([w8, w3, wB, wA]);
|
|
60
|
+
wB = wi([w9, w4, wC, wB]);
|
|
61
|
+
wC = wi([wA, w5, wD, wC]);
|
|
62
|
+
wD = wi([wB, w6, wE, wD]);
|
|
63
|
+
wE = wi([wC, w7, wF, wE]);
|
|
64
|
+
wF = wi([wD, w8, w0, wF]);
|
|
65
|
+
return [w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, wA, wB, wC, wD, wE, wF];
|
|
66
|
+
};
|
|
67
|
+
const k = [
|
|
68
|
+
[
|
|
69
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
70
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
74
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
78
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
82
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
83
|
+
],
|
|
84
|
+
];
|
|
85
|
+
const compress = ([a0, b0, c0, d0, e0, f0, g0, h0]) => data => {
|
|
86
|
+
let w = data;
|
|
87
|
+
let a = a0;
|
|
88
|
+
let b = b0;
|
|
89
|
+
let c = c0;
|
|
90
|
+
let d = d0;
|
|
91
|
+
let e = e0;
|
|
92
|
+
let f = f0;
|
|
93
|
+
let g = g0;
|
|
94
|
+
let h = h0;
|
|
95
|
+
let i = 0;
|
|
96
|
+
while (true) {
|
|
97
|
+
const ki = k[i];
|
|
98
|
+
for (let j = 0; j < 16; ++j) {
|
|
99
|
+
const t1 = h + bigSigma1(e) + ch(e)(f)(g) + ki[j] + w[j];
|
|
100
|
+
const t2 = bigSigma0(a) + maj(a)(b)(c);
|
|
101
|
+
h = g;
|
|
102
|
+
g = f;
|
|
103
|
+
f = e;
|
|
104
|
+
e = (d + t1) | 0;
|
|
105
|
+
d = c;
|
|
106
|
+
c = b;
|
|
107
|
+
b = a;
|
|
108
|
+
a = (t1 + t2) | 0;
|
|
109
|
+
}
|
|
110
|
+
if (i === 3) {
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
++i;
|
|
114
|
+
w = nextW(w);
|
|
115
|
+
}
|
|
116
|
+
return [
|
|
117
|
+
(a0 + a) | 0,
|
|
118
|
+
(b0 + b) | 0,
|
|
119
|
+
(c0 + c) | 0,
|
|
120
|
+
(d0 + d) | 0,
|
|
121
|
+
(e0 + e) | 0,
|
|
122
|
+
(f0 + f) | 0,
|
|
123
|
+
(g0 + g) | 0,
|
|
124
|
+
(h0 + h) | 0,
|
|
125
|
+
];
|
|
126
|
+
};
|
|
127
|
+
const compute = init => input => bitsCount => {
|
|
128
|
+
const { f, length } = padding(input)(bitsCount);
|
|
129
|
+
let result = init;
|
|
130
|
+
const chunkCount = length / 16;
|
|
131
|
+
for (let i = 0; i < chunkCount; i++) {
|
|
132
|
+
const s = i * 16;
|
|
133
|
+
result = compress(result)([
|
|
134
|
+
f(s + 0), f(s + 1), f(s + 2), f(s + 3), f(s + 4), f(s + 5), f(s + 6), f(s + 7),
|
|
135
|
+
f(s + 8), f(s + 9), f(s + 10), f(s + 11), f(s + 12), f(s + 13), f(s + 14), f(s + 15)
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
};
|
|
140
|
+
const init256 = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
|
|
141
|
+
export const computeSha256 = compute(init256);
|
|
142
|
+
const init224 = [0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4];
|
|
143
|
+
export const computeSha224 = compute(init224);
|
|
144
|
+
export const compress256 = compress(init256);
|
|
145
|
+
export const compress224 = compress(init224);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as _ from "./module.f.js";
|
|
2
|
+
import * as json from "../../json/module.f.js";
|
|
3
|
+
import { sort } from "../../types/object/module.f.js";
|
|
4
|
+
const toU32 = x => (x + 0x1_0000_0000) % 0x1_0000_0000;
|
|
5
|
+
const toHexString = x => toU32(x).toString(16).padStart(8, '0');
|
|
6
|
+
const stringify = a => json.stringify(sort)(a);
|
|
7
|
+
// {
|
|
8
|
+
// const result = _.padding([])(0)
|
|
9
|
+
// console.log(result.map(toHexString))
|
|
10
|
+
// }
|
|
11
|
+
// {
|
|
12
|
+
// const result = _.padding([0x61626364, 0x65000000])(40)
|
|
13
|
+
// console.log(result.map(toHexString))
|
|
14
|
+
// }
|
|
15
|
+
// {
|
|
16
|
+
// const result = _.padding([0x11111110])(31)
|
|
17
|
+
// console.log(result.map(toHexString))
|
|
18
|
+
// }
|
|
19
|
+
// {
|
|
20
|
+
// const result = _.padding([0x11111110])(32)
|
|
21
|
+
// console.log(result.map(toHexString))
|
|
22
|
+
// }
|
|
23
|
+
export default {
|
|
24
|
+
empty: {
|
|
25
|
+
sha256: () => {
|
|
26
|
+
const hash = _.computeSha256([])(0);
|
|
27
|
+
const result = stringify(hash.map(toHexString));
|
|
28
|
+
if (result !== '["e3b0c442","98fc1c14","9afbf4c8","996fb924","27ae41e4","649b934c","a495991b","7852b855"]') {
|
|
29
|
+
throw result;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
sha224: () => {
|
|
33
|
+
const hash = _.computeSha224([])(0);
|
|
34
|
+
const result = stringify(hash.map(toHexString));
|
|
35
|
+
if (result !== '["d14a028c","2a3a2bc9","476102bb","288234c4","15a2b01f","828ea62a","c5b3e42f","bdd387cb"]') {
|
|
36
|
+
throw result;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
sha224compress: [
|
|
41
|
+
() => {
|
|
42
|
+
const hash = _.compress224([0x8000_0000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
43
|
+
const result = stringify(hash.map(toHexString));
|
|
44
|
+
if (result !== '["d14a028c","2a3a2bc9","476102bb","288234c4","15a2b01f","828ea62a","c5b3e42f","bdd387cb"]') {
|
|
45
|
+
throw result;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
sha256: [
|
|
50
|
+
() => {
|
|
51
|
+
//[0x68656C6C, 0x6F20776F, 0x726C6400] represents phrase 'hello world'
|
|
52
|
+
const hash = _.computeSha256([0x68656C6C, 0x6F20776F, 0x726C6400])(88);
|
|
53
|
+
const result = stringify(hash.map(toHexString));
|
|
54
|
+
if (result !== '["b94d27b9","934d3e08","a52e52d7","da7dabfa","c484efe3","7a5380ee","9088f7ac","e2efcde9"]') {
|
|
55
|
+
throw result;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
() => {
|
|
59
|
+
//[0x68656C6C, 0x6F20776F, 0x726C6488] represents phrase 'hello world' with 1's at the end
|
|
60
|
+
const hash = _.computeSha256([0x68656C6C, 0x6F20776F, 0x726C64FF])(88);
|
|
61
|
+
const result = stringify(hash.map(toHexString));
|
|
62
|
+
if (result !== '["b94d27b9","934d3e08","a52e52d7","da7dabfa","c484efe3","7a5380ee","9088f7ac","e2efcde9"]') {
|
|
63
|
+
throw result;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
() => {
|
|
67
|
+
const input = Array(8).fill(0x31313131);
|
|
68
|
+
const result = _.computeSha256(input)(256);
|
|
69
|
+
if (toU32(result[0]) !== 0x8a83665f) {
|
|
70
|
+
throw result[0];
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
() => {
|
|
74
|
+
const input = Array(16).fill(0x31313131);
|
|
75
|
+
const hash = _.computeSha256(input)(512);
|
|
76
|
+
const result = stringify(hash.map(toHexString));
|
|
77
|
+
if (result !== '["3138bb9b","c78df27c","473ecfd1","410f7bd4","5ebac1f5","9cf3ff9c","fe4db77a","ab7aedd3"]') {
|
|
78
|
+
throw result;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const todo: () => never;
|
package/dev/module.f.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const todo = () => { throw 'not implemented'; };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as Result from '../../types/result/module.f.ts';
|
|
2
|
+
type Module = {
|
|
3
|
+
readonly default?: unknown;
|
|
4
|
+
};
|
|
5
|
+
type ModuleMap = {
|
|
6
|
+
readonly [k in string]: Module;
|
|
7
|
+
};
|
|
8
|
+
type Log<T> = (v: string) => (state: T) => T;
|
|
9
|
+
type Measure<T> = <R>(f: () => R) => (state: T) => readonly [R, number, T];
|
|
10
|
+
type Input<T> = {
|
|
11
|
+
readonly moduleMap: ModuleMap;
|
|
12
|
+
readonly log: Log<T>;
|
|
13
|
+
readonly error: Log<T>;
|
|
14
|
+
readonly measure: Measure<T>;
|
|
15
|
+
readonly state: T;
|
|
16
|
+
readonly tryCatch: <R>(f: () => R) => Result.Result<R, unknown>;
|
|
17
|
+
readonly env: (n: string) => string | undefined;
|
|
18
|
+
};
|
|
19
|
+
declare const _default: <T>(input: Input<T>) => readonly [number, T];
|
|
20
|
+
export default _default;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { entries, fold } from "../../types/list/module.f.js";
|
|
2
|
+
import { reset, fgGreen, fgRed, bold } from "../../text/sgr/module.f.js";
|
|
3
|
+
import * as Result from "../../types/result/module.f.js";
|
|
4
|
+
const isTest = s => s.endsWith('test.f.mjs') || s.endsWith('test.f.js') || s.endsWith('test.f.ts');
|
|
5
|
+
const addPass = delta => ts => ({ ...ts, time: ts.time + delta, pass: ts.pass + 1 });
|
|
6
|
+
const addFail = delta => ts => ({ ...ts, time: ts.time + delta, fail: ts.fail + 1 });
|
|
7
|
+
const timeFormat = a => {
|
|
8
|
+
const y = Math.round(a * 10_000).toString();
|
|
9
|
+
const yl = 5 - y.length;
|
|
10
|
+
const x = '0'.repeat(yl > 0 ? yl : 0) + y;
|
|
11
|
+
const s = x.length - 4;
|
|
12
|
+
const b = x.substring(0, s);
|
|
13
|
+
const e = x.substring(s);
|
|
14
|
+
return `${b}.${e} ms`;
|
|
15
|
+
};
|
|
16
|
+
export default (input) => {
|
|
17
|
+
let { moduleMap, log, error, measure, tryCatch, env, state } = input;
|
|
18
|
+
const isGitHub = env('GITHUB_ACTION') !== void 0;
|
|
19
|
+
const f = ([k, v]) => {
|
|
20
|
+
const test = i => v => ([ts, state]) => {
|
|
21
|
+
const next = test(`${i}| `);
|
|
22
|
+
switch (typeof v) {
|
|
23
|
+
case 'function': {
|
|
24
|
+
if (v.length === 0) {
|
|
25
|
+
const [[s, r], delta, state0] = measure(() => tryCatch(v))(state);
|
|
26
|
+
state = state0;
|
|
27
|
+
if (s === 'error') {
|
|
28
|
+
ts = addFail(delta)(ts);
|
|
29
|
+
if (isGitHub) {
|
|
30
|
+
// https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions
|
|
31
|
+
// https://github.com/OndraM/ci-detector/blob/main/src/Ci/GitHubActions.php
|
|
32
|
+
state = error(`::error file=${k},line=1,title=[3]['a']()::${r}`)(state);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
state = error(`${i}() ${fgRed}error${reset}, ${timeFormat(delta)}`)(state);
|
|
36
|
+
state = error(`${fgRed}${r}${reset}`)(state);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
ts = addPass(delta)(ts);
|
|
41
|
+
state = log(`${i}() ${fgGreen}ok${reset}, ${timeFormat(delta)}`)(state);
|
|
42
|
+
}
|
|
43
|
+
[ts, state] = next(r)([ts, state]);
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case 'object': {
|
|
48
|
+
if (v !== null) {
|
|
49
|
+
const f = ([k, v]) => ([time, state]) => {
|
|
50
|
+
state = log(`${i}${k}:`)(state);
|
|
51
|
+
[time, state] = next(v)([time, state]);
|
|
52
|
+
return [time, state];
|
|
53
|
+
};
|
|
54
|
+
[ts, state] = fold(f)([ts, state])(v instanceof Array ? entries(v) : Object.entries(v));
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return [ts, state];
|
|
60
|
+
};
|
|
61
|
+
return ([ts, state]) => {
|
|
62
|
+
if (isTest(k)) {
|
|
63
|
+
state = log(`testing ${k}`)(state);
|
|
64
|
+
[ts, state] = test('| ')(v.default)([ts, state]);
|
|
65
|
+
}
|
|
66
|
+
return [ts, state];
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
let ts = { time: 0, pass: 0, fail: 0 };
|
|
70
|
+
[ts, state] = fold(f)([ts, state])(Object.entries(moduleMap));
|
|
71
|
+
const fgFail = ts.fail === 0 ? fgGreen : fgRed;
|
|
72
|
+
state = log(`${bold}Number of tests: pass: ${fgGreen}${ts.pass}${reset}${bold}, fail: ${fgFail}${ts.fail}${reset}${bold}, total: ${ts.pass + ts.fail}${reset}`)(state);
|
|
73
|
+
state = log(`${bold}Time: ${timeFormat(ts.time)}${reset}`)(state);
|
|
74
|
+
return [ts.fail !== 0 ? 1 : 0, state];
|
|
75
|
+
};
|
package/dev/test.f.d.ts
ADDED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
const assert
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const assert_if
|
|
6
|
-
: (_: boolean) => void
|
|
7
|
-
= c => { if (c) { throw 'assert_if' } }
|
|
8
|
-
|
|
1
|
+
const assert = () => { throw 'assert'; };
|
|
2
|
+
const assert_if = c => { if (c) {
|
|
3
|
+
throw 'assert_if';
|
|
4
|
+
} };
|
|
9
5
|
export default {
|
|
10
6
|
ctor: () => {
|
|
11
|
-
const c = (() => { })['constructor']
|
|
12
|
-
const f = c('return 5')
|
|
13
|
-
const result = f()
|
|
14
|
-
if (result !== 5) {
|
|
7
|
+
const c = (() => { })['constructor'];
|
|
8
|
+
const f = c('return 5');
|
|
9
|
+
const result = f();
|
|
10
|
+
if (result !== 5) {
|
|
11
|
+
throw 'function';
|
|
12
|
+
}
|
|
15
13
|
},
|
|
16
14
|
ctorEmpty: () => {
|
|
17
15
|
/** @type {any} */
|
|
18
|
-
const o = {}
|
|
19
|
-
const c = o['constructor']
|
|
16
|
+
const o = {};
|
|
17
|
+
const c = o['constructor'];
|
|
20
18
|
// console.log(c)
|
|
21
19
|
// console.log(c(()=>{}))
|
|
22
20
|
},
|
|
@@ -24,19 +22,19 @@ export default {
|
|
|
24
22
|
/** @type {any} */
|
|
25
23
|
const o = {
|
|
26
24
|
constructor: void 0
|
|
27
|
-
}
|
|
28
|
-
const c = o['constructor']
|
|
25
|
+
};
|
|
26
|
+
const c = o['constructor'];
|
|
29
27
|
//console.log(c)
|
|
30
28
|
},
|
|
31
29
|
number: () => {
|
|
32
30
|
/** @type {any} */
|
|
33
|
-
const b = '42'
|
|
34
|
-
const r = Number(b)
|
|
31
|
+
const b = '42';
|
|
32
|
+
const r = Number(b);
|
|
35
33
|
//console.log(r)
|
|
36
34
|
},
|
|
37
35
|
properties: () => {
|
|
38
36
|
/** @type {any} */
|
|
39
|
-
const o = {}
|
|
37
|
+
const o = {};
|
|
40
38
|
//const c = o['constructor']
|
|
41
39
|
//const c = o['__proto__']
|
|
42
40
|
//const c = o['__defineGetter__']
|
|
@@ -47,12 +45,12 @@ export default {
|
|
|
47
45
|
//const c = o['isPrototypeOf']
|
|
48
46
|
//const c = o['propertyIsEnumerable']
|
|
49
47
|
//const c = o['toString']
|
|
50
|
-
const c = o['valueOf']
|
|
48
|
+
const c = o['valueOf'];
|
|
51
49
|
//console.log(c)
|
|
52
50
|
},
|
|
53
51
|
getOwnPropertyDescriptor: () => {
|
|
54
|
-
const x = { 'a': 12 }
|
|
55
|
-
const c = Object.getOwnPropertyDescriptor(x, 'constructor')
|
|
56
|
-
const a = Object.getOwnPropertyDescriptor(x, 'a')
|
|
52
|
+
const x = { 'a': 12 };
|
|
53
|
+
const c = Object.getOwnPropertyDescriptor(x, 'constructor');
|
|
54
|
+
const a = Object.getOwnPropertyDescriptor(x, 'a');
|
|
57
55
|
}
|
|
58
|
-
}
|
|
56
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as list from '../types/list/module.f.ts';
|
|
2
|
+
import * as O from '../types/object/module.f.ts';
|
|
3
|
+
type Object = {
|
|
4
|
+
readonly [k in string]: Unknown;
|
|
5
|
+
};
|
|
6
|
+
type Array = readonly Unknown[];
|
|
7
|
+
type Unknown = Object | boolean | string | number | null | Array | bigint | undefined;
|
|
8
|
+
type Entry = O.Entry<Unknown>;
|
|
9
|
+
type Entries = list.List<Entry>;
|
|
10
|
+
type MapEntries = (entries: Entries) => Entries;
|
|
11
|
+
export declare const serialize: (mapEntries: MapEntries) => (value: Unknown) => list.List<string>;
|
|
12
|
+
/**
|
|
13
|
+
* The standard `JSON.stringify` rules determined by
|
|
14
|
+
* https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
|
|
15
|
+
*/
|
|
16
|
+
export declare const stringify: (mapEntries: MapEntries) => (value: Unknown) => string;
|
|
17
|
+
export {};
|