Skip to content

Commit

Permalink
remove separate keys module
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser authored and mainnet-pat committed Sep 5, 2024
1 parent 53e77b6 commit 4e28ca7
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 61 deletions.
22 changes: 0 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Oz -s EXCEPTION_CATCHING_ALL
add_definitions(-DAUTO_INITIALIZE_EASYLOGGINGPP -DNO_AES)

set(BUILD_MONERO_WALLET_FULL_WASM ON)
set(BUILD_MONERO_WALLET_KEYS_WASM ON)

##############
# C++ bridge
Expand Down Expand Up @@ -306,12 +305,6 @@ EMCC_LINKER_FLAGS_BASE
# -g \
)

set(
EMCC_LINKER_FLAGS_KEYS
"${EMCC_LINKER_FLAGS_BASE} \
"
)

set(
EMCC_LINKER_FLAGS_FULL
"${EMCC_LINKER_FLAGS_BASE} \
Expand All @@ -320,27 +313,12 @@ EMCC_LINKER_FLAGS_FULL
"
)

message(STATUS "EMCC_LINKER_FLAGS_KEYS ${EMCC_LINKER_FLAGS_KEYS}")
message(STATUS "EMCC_LINKER_FLAGS_FULL ${EMCC_LINKER_FLAGS_FULL}")

####################
# Build targets
####################

if (BUILD_MONERO_WALLET_KEYS_WASM)
add_executable(monero_wallet_keys ${MONERO_WALLET_KEYS_SRC_FILES})
set_target_properties(monero_wallet_keys PROPERTIES LINK_FLAGS "${EMCC_LINKER_FLAGS_KEYS}")
target_link_libraries(
monero_wallet_keys
#
boost_chrono
boost_system
boost_thread
#
${log-lib}
)
endif()

if (BUILD_MONERO_WALLET_FULL_WASM)
add_executable(monero_wallet_full ${MONERO_WALLET_FULL_SRC_FILES} ${MONERO_WALLET_KEYS_SRC_FILES})
set_target_properties(monero_wallet_full PROPERTIES LINK_FLAGS "${EMCC_LINKER_FLAGS_FULL}")
Expand Down
5 changes: 0 additions & 5 deletions bin/build_wasm_emscripten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ emmake cmake --build . -j$HOST_NCORES || exit 1
# move available wasm files to ./dist
cd ..
mkdir -p ./dist || exit 1
[ -f ./build/monero_wallet_keys.js ] \
&& {
mv ./build/monero_wallet_keys.js ./dist/
}

[ -f ./build/monero_wallet_full.js ] \
&& {
mv ./build/monero_wallet_full.js ./dist/
Expand Down
2 changes: 1 addition & 1 deletion bin/postprocess_wasm.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs";
import { Buffer } from "buffer";

const fileNames = ["./dist/monero_wallet_full.js", "./dist/monero_wallet_keys.js"];
const fileNames = ["./dist/monero_wallet_full.js"];


const postprocess = async (fileName) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build_web_tests": "webpack --config ./webpack.tests.js",
"test": "npm run build_commonjs && node --enable-source-maps node_modules/mocha/bin/_mocha --require @babel/register \"dist/src/test/TestAll\" --timeout 900000000 --exit",
"typedoc": "typedoc ./index.ts --out ./docs/typedocs --excludePrivate --disableSources",
"build_commonjs": "babel ./src --extensions \".js,.ts\" --out-dir ./dist/src && babel ./index.ts --extensions \".ts\" --out-dir ./dist && shx mkdir -p dist/dist && shx cp dist/monero_wallet_full.js dist/monero_wallet_keys.js dist/dist && shx cp dist/*.js.map dist/dist",
"build_commonjs": "babel ./src --extensions \".js,.ts\" --out-dir ./dist/src && babel ./index.ts --extensions \".ts\" --out-dir ./dist && shx mkdir -p dist/dist && shx cp dist/monero_wallet_full.js dist/dist && shx cp dist/*.js.map dist/dist",
"check_babel_version": "babel -V"
},
"build": {
Expand Down
21 changes: 0 additions & 21 deletions src/main/ts/common/LibraryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,10 @@ export default class LibraryUtils {
return LibraryUtils.WASM_MODULE;
}

/**
* Load the WebAssembly keys module with caching.
*/
static async loadKeysModule() {

// use cache if suitable, full module supersedes keys module because it is superset
if (LibraryUtils.WASM_MODULE) return LibraryUtils.WASM_MODULE;

// load module
const fetch_ = globalThis.fetch;
globalThis.fetch = undefined; // prevent fetch in worker
let module = await require("../../../../dist/monero_wallet_keys")();
globalThis.fetch = fetch_;
LibraryUtils.WASM_MODULE = module;
delete LibraryUtils.WASM_MODULE.then;
LibraryUtils.initWasmModule(LibraryUtils.WASM_MODULE);
return module;
}

/**
* Load the WebAssembly full module with caching.
*
* The full module is a superset of the keys module and overrides it.
*
* TODO: this is separate static function from loadKeysModule() because webpack cannot bundle worker using runtime param for conditional import
*/
static async loadFullModule() {

Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/common/MoneroRpcConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export default class MoneroRpcConnection {
*/
async checkConnection(timeoutMs): Promise<boolean> {
return this.queueCheckConnection(async () => {
await LibraryUtils.loadKeysModule(); // cache wasm for binary request
await LibraryUtils.loadFullModule(); // cache wasm for binary request
let isOnlineBefore = this.isOnline;
let isAuthenticatedBefore = this.isAuthenticated;
let startTime = Date.now();
Expand Down
10 changes: 5 additions & 5 deletions src/main/ts/common/MoneroUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default class MoneroUtils {
assert(GenUtils.isBase58(standardAddress), "Address is not base 58");

// load keys module by default
if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadKeysModule();
if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadFullModule();

// get integrated address in queue
return LibraryUtils.getWasmModule().queueTask(async () => {
Expand Down Expand Up @@ -204,7 +204,7 @@ export default class MoneroUtils {
networkType = MoneroNetworkType.from(networkType);

// load keys module by default
if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadKeysModule();
if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadFullModule();

// validate address in queue
return LibraryUtils.getWasmModule().queueTask(async function() {
Expand Down Expand Up @@ -308,7 +308,7 @@ export default class MoneroUtils {
if (MoneroUtils.PROXY_TO_WORKER) return LibraryUtils.invokeWorker(undefined, "moneroUtilsJsonToBinary", Array.from(arguments));

// load keys module by default
if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadKeysModule();
if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadFullModule();

// use wasm in queue
return LibraryUtils.getWasmModule().queueTask(async function() {
Expand Down Expand Up @@ -345,7 +345,7 @@ export default class MoneroUtils {
if (MoneroUtils.PROXY_TO_WORKER) return LibraryUtils.invokeWorker(undefined, "moneroUtilsBinaryToJson", Array.from(arguments));

// load keys module by default
if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadKeysModule();
if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadFullModule();

// use wasm in queue
return LibraryUtils.getWasmModule().queueTask(async function() {
Expand Down Expand Up @@ -382,7 +382,7 @@ export default class MoneroUtils {
if (MoneroUtils.PROXY_TO_WORKER) return LibraryUtils.invokeWorker(undefined, "moneroUtilsBinaryBlocksToJson", Array.from(arguments));

// load keys module by default
if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadKeysModule();
if (LibraryUtils.getWasmModule() === undefined) await LibraryUtils.loadFullModule();

// use wasm in queue
return LibraryUtils.getWasmModule().queueTask(async function() {
Expand Down
8 changes: 4 additions & 4 deletions src/main/ts/wallet/MoneroWalletKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class MoneroWalletKeys extends MoneroWallet {
if (config.getLanguage() === undefined) config.setLanguage("English");

// load wasm module
let module = await LibraryUtils.loadKeysModule();
let module = await LibraryUtils.loadFullModule();

// queue call to wasm module
return module.queueTask(async () => {
Expand All @@ -107,7 +107,7 @@ export class MoneroWalletKeys extends MoneroWallet {
if (config.getLanguage() !== undefined) throw new MoneroError("Cannot provide language when creating wallet from seed");

// load wasm module
let module = await LibraryUtils.loadKeysModule();
let module = await LibraryUtils.loadFullModule();

// queue call to wasm module
return module.queueTask(async () => {
Expand All @@ -133,7 +133,7 @@ export class MoneroWalletKeys extends MoneroWallet {
if (config.getLanguage() === undefined) config.setLanguage("English");

// load wasm module
let module = await LibraryUtils.loadKeysModule();
let module = await LibraryUtils.loadFullModule();

// queue call to wasm module
return module.queueTask(async () => {
Expand All @@ -149,7 +149,7 @@ export class MoneroWalletKeys extends MoneroWallet {
}

static async getSeedLanguages(): Promise<string[]> {
let module = await LibraryUtils.loadKeysModule();
let module = await LibraryUtils.loadFullModule();
return module.queueTask(async () => {
return JSON.parse(module.get_keys_wallet_seed_languages()).languages;
});
Expand Down
2 changes: 1 addition & 1 deletion src/test/TestMoneroWalletCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class TestMoneroWalletCommon {
this.wallet = await this.getTestWallet();
this.daemon = await this.getTestDaemon();
TestUtils.WALLET_TX_TRACKER.reset(); // all wallets need to wait for txs to confirm to reliably sync
await LibraryUtils.loadKeysModule(); // for wasm dependents like address validation
await LibraryUtils.loadFullModule(); // for wasm dependents like address validation
}

/**
Expand Down

0 comments on commit 4e28ca7

Please sign in to comment.