Closed paulshapiro closed 5 years ago
Yes, it's because emscripten now builds wasm instead of asm.js, which is must faster than the latter, but must be loaded asynchronously. If you want, you can build the library for asm.js instead (see the CMakeLists file.).
The Electron-related code snippets are merely there to facilitate calling the functions over IPC. There are no actual electron includes or special code. It just looks at a global and includes a very vanilla module to either throw or not throw. They don't affect your dependencies when you want to run it in any other environment. It's not optimized for MyMonero any more than the previous version of the library was, and in fact, we are receiving requests to add bridging to various other functions like decodeRct
and are in the process of adding them as much as people are actually communicating their wishes with us. Given that our new setup is significantly faster than any asm.js build or hand-coded JS, and given the future bringing new implementations which are prohibitive to re-implement by hand in JS such as bulletproofs, we would like this library to support the various crypto utils cases going forward. However we have chosen to expose certain functions with their actual implementations in C++ in order to share code across implementations and in order to achieve maximal performance.
Thanks for your question.
@paulshapiro Thanks for the good explanations. Just as a JS developer this API is not really looking good:
const args_str = '{"nettype_string":"MAINNET","from_address_string":"..."}';
const ret_string = Module.create_transaction(args_str);
Can the bindings be improved to something like below?
const ret_string = Module.createTransaction({nettypeString: "MAINNET"});
@p0o that is not the API you should use. You're trying to interact directly with the emscripten module. A ton of work has been done so you don't have to...
@paulshapiro ah my bad, so I should use the functions in MyMoneroCoreBridge
only? In that case I say it was better to write the tests with that API. Most devs would read the tests to know how to use the library.
You're free to use it however you want :P
And yeah docs for the core-js API here coming soon, feel free to PR since it's stable enough that we documented the JSON bridge
https://github.com/mymonero/mymonero-core-cpp - Readme - API Documentation
I recently added a bunch of commonly requested crypto functions in this commit: https://github.com/mymonero/mymonero-core-js/commit/299c0c4bd65e29a5983361bbf478ddcc14d9ecd8
address_and_keys_from_seed
(aka create_address
in previous mymonero-core-js), generate_key_derivation
, derive_public_key
, derive_subaddress_public_key
, and decodeRct
This PR replaces the existing hand-modified
cryptonote_crypto_EMSCRIPTEN.js
file with an automatically builtMyMoneroCoreCpp.js
and.wasm
fileset. This is called by amodifiednew file,cryptonote_utils.js
fileMyMoneroCoreBridge.js
.This work is an incremental step towards the real overhaul of the API, in which the majority of mymonero_core_js implementation (including, for example, mnemonics) will be shifted to C++. The C++ work for that has basically been completed and is getting final testing and possibly additional minor functions (this reimplementation solves #13 and much of #18). In the meantime, this PR, which now only demonstrates reimplementing the initial function of cryptonote_crypto_EMSCRIPTEN by transpilingcrypto-ops.c
, is being made available for review given its essential functionality.This PR solves e.g. #8, #7, #1, #50.
The C++ reimplementation (located at https://github.com/mymonero/mymonero-core-cpp) solves #13 (pending bulletproofs implementation stabilization), and since it hooks into Monero's cryptonote_core, it also includes fundamental support for hw devices (#18).
Calling all experienced C++ and Monero developers! The C++ reimplementation needs review. See https://github.com/mymonero/mymonero-core-cpp/issues/6 and https://github.com/mymonero/mymonero-core-cpp/issues/7
Bulletproofs can be enabled and updated per https://github.com/mymonero/mymonero-core-cpp/issues/4
Improvements to error messages can be done per https://github.com/mymonero/mymonero-core-cpp/issues/3
Multisig transaction support has not been added but this PR enables exposing the multisig functionality which is latent in the shared
cryptonote::create_tx_…
function.Most of the JS in this repo has been condensed into a single file:
cryptonote_utils.js
MyMoneroCoreBridge.js
. This file was adapted from the oldcryptonote_utils.js
and now focuses on being a bridge to emscripten by managing dependency loading and serialization. An interface to this core bridge is provided in the familiar filemonero_utils.js
, which is the entrypoint for all core calls.monero_utils
now exports a promise, theresolve
of which must be waited upon before calls can be made, which have all been able to remain synchronous. Sincemonero_utils
must be waited upon, synchronous higher level functions which requiremonero_utils
such as the lazy key image generator factory accessor now take aresolve
edmonero_utils
as an argument. If you're includingmonero_utils
from an Electron renderer process, it automatically bridges to include the actual core bridge + wasm on the main process and relays err_msgs over IPC so that they getthrow
n on the renderer process rather than breaking the IPC call.Many files have been removed… especially the various JS crypto implementations like nacl, sha3, mnemonics... Some fixes and additional features have been gained, such as a full range of mnemonic languages, and much better support for decoding mnemonics with misspellings.
There are some significant API changes, but the JSON bridge to C++ is extremely simple and almost equivalent in content to the existing JS APIs. This JSON API is fully documented in the readme at https://github.com/mymonero/mymonero-core-cpp.
Currently,
SendFunds()
remains implemented in JS (inmonero_sendingFunds_utils
). There's an item to implement it in C++: https://github.com/mymonero/mymonero-core-cpp/issues/5Fee estimation (which has been updated for bulletproofs) and therefore(Resolved)fixedMixin()
have been kept in JS to solve race condition with wasm load: https://github.com/mymonero/mymonero-core-js/issues/53Performance of the wasm code should be tested with exception catching on in the emscripten build pipeline: https://github.com/mymonero/mymonero-core-js/issues/52
Money (JSBigInt) amount formatting and tx parsing were moved from
cryptonote_utils
tomoney_format_utils
(https://github.com/mymonero/mymonero-core-js/issues/50) andmonero_txParsing_utils
respectively. Access the Monero amount formatter via index.monero_amount_format_utils orrequire
it directly.tx_key
now returned bycreate_transaction
.