This guide assumes you are using a Linux distro with build tools installed.
You can read https://emscripten.org/docs/getting_started/downloads.html to help you install the Emscripten toolchain.
You can use git
to clone the repo.
git clone github.com/dogecoinfoundation/libdogecoin
First run:
./autogen.sh
Then run the configure script:
Note: Change /usr/lib/emscripten
to your SDK path. <emsdk root directory>
/usr/lib/emscripten/emconfigure ./configure CC=/usr/lib/emscripten/emcc AR=/usr/lib/emscripten/emar --host wasm32-emscripten --disable-net --disable-dependency-tracking
To compile, type:
/usr/lib/emscripten/emmake make
Wait until the compiling process is finished.
To convert the resulting library (libdogecoin.a
) into a usable JS file, run these commands:
Note: Change /usr/lib/emscripten
to your SDK path. <emsdk root directory>
Functions that you want to use in the JS needs to maunally exported. To add a function, add it to sEXPORTED_FUNCTIONS=
by typing a _
and the function name.
The resulting file will be called libdogecoin.js
cd .libs
/usr/lib/emscripten/emcc -sEXPORTED_FUNCTIONS=_dogecoin_ecc_start,_dogecoin_ecc_stop,_generatePrivPubKeypair,_free,_malloc -sEXPORTED_RUNTIME_METHODS=ccall,cwrap,allocate libdogecoin.a ../src/secp256k1/.libs/libsecp256k1.a -o libdogecoin.js
To use this JS file, you can include it in a HTML file:
<script src="libdogecoin.js"/>
<script>
Module.onRuntimeInitialized = _ => {
_dogecoin_ecc_start()
var privatePtr = allocate(intArrayFromString(""), ALLOC_NORMAL);
var publicPtr = allocate(intArrayFromString(""), ALLOC_NORMAL);
_generatePrivPubKeypair(privatePtr, publicPtr, false)
var privKey = UTF8ToString(privatePtr)
var pubKey = UTF8ToString(publicPtr)
document.write(`Public key: ${pubKey} <br> Private Ket ${privKey}`);
_dogecoin_ecc_stop()
_free(privatePtr)
_free(publicPtr)
}
</script>
NOTE: A web server is required for this to work. You can easily run a server using python3 by typing:
python -m http.server