forked from bitcoinjs/tiny-secp256k1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
147 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "util/gen-fixtures/secp256k1"] | ||
path = util/gen-fixtures/secp256k1 | ||
url = https://github.com/bitcoin-core/secp256k1.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/target | ||
/util/gen-fixtures/secp256k1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
all: json-privates json-points json-ecdsa | ||
|
||
.PHONY: secp256k1 | ||
secp256k1: | ||
cd secp256k1 && ./autogen.sh && ./configure && make | ||
|
||
privates: secp256k1 | ||
privates: privates.cpp shared.hpp | ||
g++ $< -Lsecp256k1/.libs/ -lgmp -l:libsecp256k1.a -o $@ | ||
|
||
points: secp256k1 | ||
points: points.cpp shared.hpp | ||
g++ $< -Lsecp256k1/.libs/ -lgmp -l:libsecp256k1.a -o $@ | ||
|
||
ecdsa: secp256k1 | ||
ecdsa: ecdsa.cpp shared.hpp | ||
g++ $< -Lsecp256k1/.libs/ -lgmp -lcrypto -lssl -l:libsecp256k1.a -o $@ | ||
|
||
clean: | ||
rm privates points ecdsa && cd secp256k1 && make clean | ||
|
||
json-points: points | ||
./points | jq . > ../../tests/fixtures/points.json | ||
|
||
json-privates: privates | ||
./privates | jq . > ../../tests/fixtures/privates.json | ||
|
||
json-ecdsa: ecdsa | ||
./ecdsa | jq . > ../../tests/fixtures/ecdsa.json |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const fs = require("fs"); | ||
const binaryen = require("binaryen"); | ||
|
||
const NOT_USED_FUNCTIONS = [ | ||
"rustsecp256k1_v0_4_0_default_error_callback_fn", | ||
"rustsecp256k1_v0_4_0_default_illegal_callback_fn", | ||
"rustsecp256k1_v0_4_0_context_preallocated_clone_size", | ||
"rustsecp256k1_v0_4_0_context_preallocated_clone", | ||
"rustsecp256k1_v0_4_0_context_preallocated_destroy", | ||
"rustsecp256k1_v0_4_0_context_set_illegal_callback", | ||
"rustsecp256k1_v0_4_0_context_set_error_callback", | ||
"rustsecp256k1_v0_4_0_ecdsa_signature_parse_der", | ||
"rustsecp256k1_v0_4_0_ecdsa_signature_serialize_der", | ||
"rustsecp256k1_v0_4_0_ec_seckey_verify", | ||
"rustsecp256k1_v0_4_0_ec_privkey_negate", | ||
"rustsecp256k1_v0_4_0_ec_pubkey_negate", | ||
"rustsecp256k1_v0_4_0_ec_privkey_tweak_add", | ||
"rustsecp256k1_v0_4_0_ec_seckey_tweak_mul", | ||
"rustsecp256k1_v0_4_0_ec_privkey_tweak_mul", | ||
]; | ||
const NOT_USED_GLOBALS = ["rustsecp256k1_v0_4_0_nonce_function_default"]; | ||
|
||
const NOT_EXPORTED_FUNCTIONS = [ | ||
"rustsecp256k1_v0_4_0_context_preallocated_size", | ||
"rustsecp256k1_v0_4_0_context_preallocated_create", | ||
"rustsecp256k1_v0_4_0_context_randomize", | ||
"rustsecp256k1_v0_4_0_context_no_precomp", | ||
"rustsecp256k1_v0_4_0_ec_pubkey_parse", | ||
"rustsecp256k1_v0_4_0_ec_pubkey_combine", | ||
"rustsecp256k1_v0_4_0_ec_pubkey_serialize", | ||
"rustsecp256k1_v0_4_0_ec_pubkey_tweak_add", | ||
"rustsecp256k1_v0_4_0_ec_pubkey_create", | ||
"rustsecp256k1_v0_4_0_ec_pubkey_tweak_mul", | ||
"rustsecp256k1_v0_4_0_ec_seckey_tweak_add", | ||
"rustsecp256k1_v0_4_0_ec_seckey_negate", | ||
"rustsecp256k1_v0_4_0_nonce_function_rfc6979", | ||
"rustsecp256k1_v0_4_0_ecdsa_sign", | ||
"rustsecp256k1_v0_4_0_ecdsa_signature_serialize_compact", | ||
"rustsecp256k1_v0_4_0_ecdsa_signature_parse_compact", | ||
"rustsecp256k1_v0_4_0_ecdsa_signature_normalize", | ||
"rustsecp256k1_v0_4_0_ecdsa_verify", | ||
]; | ||
|
||
function strip(input) { | ||
const module = binaryen.readBinary(input); | ||
|
||
for (const name of NOT_USED_FUNCTIONS) { | ||
module.removeFunction(name); | ||
module.removeExport(name); | ||
} | ||
for (const name of NOT_USED_GLOBALS) { | ||
module.removeGlobal(name); | ||
module.removeExport(name); | ||
} | ||
|
||
for (const name of NOT_EXPORTED_FUNCTIONS) { | ||
module.removeExport(name); | ||
} | ||
|
||
return module.emitBinary(); | ||
} | ||
|
||
function main(location) { | ||
const input = fs.readFileSync(location); | ||
const output = strip(input); | ||
|
||
const change = input.length - output.length; | ||
console.log(`Size: ${input.length} -> ${output.length} (save ${change}+)`); | ||
|
||
fs.writeFileSync(location, output); | ||
} | ||
|
||
main(process.argv[2]); |