Skip to content

Commit

Permalink
refactor mnemonic to seed (breaking change)
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Jul 24, 2023
1 parent 9623240 commit b27f8bf
Show file tree
Hide file tree
Showing 23 changed files with 324 additions and 336 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ let primaryAddress = await walletRpc.getPrimaryAddress(); // 555zgduFhmKd2o8rPUz
let balance = await walletRpc.getBalance(); // 533648366742
let txs = await walletRpc.getTxs(); // get transactions containing transfers to/from the wallet

// create wallet from mnemonic phrase using WebAssembly bindings to monero-project
// create wallet from seed phrase using WebAssembly bindings to monero-project
let walletFull = await monerojs.createWalletFull({
path: "sample_wallet_full",
password: "supersecretpassword123",
networkType: "stagenet",
serverUri: "http://localhost:38081",
serverUsername: "superuser",
serverPassword: "abctesting123",
mnemonic: "hefty value scenic...",
seed: "hefty value scenic...",
restoreHeight: 573936,
});

Expand Down
6 changes: 3 additions & 3 deletions docs/developer_guide/creating_wallets.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let walletRpc = await monerojs.connectToWalletRpc("http://localhost:38081", "sup
await walletRpc.createWallet({
path: "mywallet",
password: "supersecretpassword",
mnemonic: "coexist igloo pamphlet lagoon...",
seed: "coexist igloo pamphlet lagoon...",
restoreHeight: 1543218
});
```
Expand All @@ -43,7 +43,7 @@ let wallet = await monerojs.createWalletFull({
path: "./test_wallets/wallet1", // leave blank for in-memory wallet
password: "supersecretpassword",
networkType: "stagenet",
mnemonic: "coexist igloo pamphlet lagoon...",
seed: "coexist igloo pamphlet lagoon...",
restoreHeight: 1543218,
serverUri: "http://localhost:38081",
serverUsername: "daemon_user",
Expand All @@ -65,6 +65,6 @@ let monerojs = require("monero-javascript");
let wallet = await monerojs.createWalletKeys({
password: "abc123",
networkType: MoneroNetworkType.STAGENET,
mnemonic: "coexist igloo pamphlet lagoon..."
seed: "coexist igloo pamphlet lagoon..."
});
```
4 changes: 2 additions & 2 deletions docs/developer_guide/getting_started_p1.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ The offline wallet generator displays four basic wallet attributes:

Wallet getters are used to obtain wallet attributes and log them to the console:
```
console.log("Mnemonic phrase: " + await walletKeys.getMnemonic());
console.log("Mnemonic phrase: " + await walletKeys.getSeed());
console.log("Address: " + await walletKeys.getAddress(0,0)); // get address of account 0, subaddress 0
console.log("Spend key: " + await walletKeys.getPrivateSpendKey());
console.log("View key: " + await walletKeys.getPrivateViewKey());
Expand All @@ -88,7 +88,7 @@ async function main() {
let walletKeys = await monerojs.createWalletKeys({networkType: "stagenet", language: "English"});
// print wallet attributes
console.log("Mnemonic phrase: " + await walletKeys.getMnemonic());
console.log("Mnemonic phrase: " + await walletKeys.getSeed());
console.log("Address: " + await walletKeys.getAddress(0,0)); // get address of account 0, subaddress 0
console.log("Spend key: " + await walletKeys.getPrivateSpendKey());
console.log("View key: " + await walletKeys.getPrivateViewKey());
Expand Down
8 changes: 4 additions & 4 deletions docs/developer_guide/getting_started_p2.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ _Note: In order for the server to reflect changes to source files, you need to s
let walletKeys = await monerojs.createWalletKeys({networkType: "stagenet", language: "English"});

// print wallet attributes
console.log("Mnemonic phrase: " + await walletKeys.getMnemonic());
console.log("Mnemonic phrase: " + await walletKeys.getSeed());
console.log("Address: " + await walletKeys.getAddress(0,0)); // get address of account 0, subaddress 0
console.log("Spend key: " + await walletKeys.getPrivateSpendKey());
console.log("View key: " + await walletKeys.getPrivateViewKey());
Expand Down Expand Up @@ -103,7 +103,7 @@ Add "div" elements between the opening and closing "body" tags to display each w
Open offline_wallet_generator.js and find the lines that the print the wallet attributes to the console:

```
console.log("Mnemonic phrase: " + await walletKeys.getMnemonic());
console.log("Mnemonic phrase: " + await walletKeys.getSeed());
console.log("Address: " + await walletKeys.getAddress(0,0)); // get address of account 0, subaddress 0
console.log("Spend key: " + await walletKeys.getPrivateSpendKey());
console.log("View key: " + await walletKeys.getPrivateViewKey());
Expand All @@ -113,7 +113,7 @@ Modify these lines to assign each string to its corresponding div element in ind

```
// print the wallet's attributes in the browser window
document.getElementById("wallet_mnemonic_phrase").innerHTML = "Mnemonic phrase: " + await walletKeys.getMnemonic();
document.getElementById("wallet_mnemonic_phrase").innerHTML = "Mnemonic phrase: " + await walletKeys.getSeed();
document.getElementById("wallet_address").innerHTML = "Address: " + await walletKeys.getAddress(0, 0); // get address of account 0, subaddress 0
document.getElementById("wallet_spend_key").innerHTML = "Spend key: " + await walletKeys.getPrivateSpendKey();
document.getElementById("wallet_view_key").innerHTML = "View key: " + await walletKeys.getPrivateViewKey();
Expand Down Expand Up @@ -153,7 +153,7 @@ async function main() {
let walletKeys = await monerojs.createWalletKeys({networkType: "stagenet", language: "English"});
// print the wallet's attributes in the browser window
document.getElementById("wallet_mnemonic_phrase").innerHTML = "Mnemonic phrase: " + await walletKeys.getMnemonic();
document.getElementById("wallet_mnemonic_phrase").innerHTML = "Mnemonic phrase: " + await walletKeys.getSeed();
document.getElementById("wallet_address").innerHTML = "Address: " + await walletKeys.getAddress(0, 0); // get address at account 0, subaddress 0
document.getElementById("wallet_spend_key").innerHTML = "Spend key: " + await walletKeys.getPrivateSpendKey();
document.getElementById("wallet_view_key").innerHTML = "View key: " + await walletKeys.getPrivateViewKey();
Expand Down
2 changes: 1 addition & 1 deletion docs/developer_guide/view_only_offline.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ await viewOnlyWallet.sync();
let offlineWallet = await monerojs.createWalletFull({
path: "my_offline_wallet",
networkType: "stagenet",
mnemonic: "spying swept ashtray going hence jester swagger cease spying unusual..."
seed: "spying swept ashtray going hence jester swagger cease spying unusual..."
});

// export outputs from view-only wallet
Expand Down
10 changes: 5 additions & 5 deletions src/main/cpp/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ EMSCRIPTEN_BINDINGS(module)

emscripten::function("open_wallet_full", &monero_wasm_bridge::open_wallet_full);
emscripten::function("create_full_wallet", &monero_wasm_bridge::create_full_wallet);
emscripten::function("get_full_wallet_mnemonic_languages", &monero_wasm_bridge::get_full_wallet_mnemonic_languages);
emscripten::function("get_full_wallet_seed_languages", &monero_wasm_bridge::get_full_wallet_seed_languages);

emscripten::function("create_keys_wallet_random", &monero_wasm_bridge::create_keys_wallet_random);
emscripten::function("create_keys_wallet_from_mnemonic", &monero_wasm_bridge::create_keys_wallet_from_mnemonic);
emscripten::function("create_keys_wallet_from_seed", &monero_wasm_bridge::create_keys_wallet_from_seed);
emscripten::function("create_keys_wallet_from_keys", &monero_wasm_bridge::create_keys_wallet_from_keys);
emscripten::function("get_keys_wallet_mnemonic_languages", &monero_wasm_bridge::get_keys_wallet_mnemonic_languages);
emscripten::function("get_keys_wallet_seed_languages", &monero_wasm_bridge::get_keys_wallet_seed_languages);

// ----------------------- WALLET INSTANCE METHODS --------------------------

Expand All @@ -36,8 +36,8 @@ EMSCRIPTEN_BINDINGS(module)
emscripten::function("is_connected_to_daemon", &monero_wasm_bridge::is_connected_to_daemon);
emscripten::function("get_daemon_max_peer_height", &monero_wasm_bridge::get_daemon_max_peer_height);
emscripten::function("get_version", &monero_wasm_bridge::get_version);
emscripten::function("get_mnemonic", &monero_wasm_bridge::get_mnemonic);
emscripten::function("get_mnemonic_language", &monero_wasm_bridge::get_mnemonic_language);
emscripten::function("get_seed", &monero_wasm_bridge::get_seed);
emscripten::function("get_seed_language", &monero_wasm_bridge::get_seed_language);
emscripten::function("get_private_spend_key", &monero_wasm_bridge::get_private_spend_key);
emscripten::function("get_private_view_key", &monero_wasm_bridge::get_private_view_key);
emscripten::function("get_public_view_key", &monero_wasm_bridge::get_public_view_key);
Expand Down
34 changes: 20 additions & 14 deletions src/main/cpp/monero_wasm_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,48 +190,54 @@ void monero_wasm_bridge::create_full_wallet(const string& config_json, const str
#endif
}

string monero_wasm_bridge::get_full_wallet_mnemonic_languages() {
string monero_wasm_bridge::get_full_wallet_seed_languages() {
#if defined BUILD_WALLET_FULL
rapidjson::Document doc;
doc.SetObject();
doc.AddMember("languages", monero_utils::to_rapidjson_val(doc.GetAllocator(), monero_wallet_full::get_mnemonic_languages()), doc.GetAllocator());
doc.AddMember("languages", monero_utils::to_rapidjson_val(doc.GetAllocator(), monero_wallet_full::get_seed_languages()), doc.GetAllocator());
return monero_utils::serialize(doc);
#else
throw runtime_error("monero_wallet_full not built");
#endif
}

void monero_wasm_bridge::create_keys_wallet_random(int network_type, const string& language, emscripten::val callback) {
void monero_wasm_bridge::create_keys_wallet_random(const string& config_json, emscripten::val callback) {
try {
monero_wallet* wallet = monero_wallet_keys::create_wallet_random(static_cast<monero_network_type>(network_type), language);
shared_ptr<monero_wallet_config> config = monero_wallet_config::deserialize(config_json);
config->m_path = std::string("");
monero_wallet* wallet = monero_wallet_keys::create_wallet_random(*config);
callback((int) wallet); // callback with wallet memory address
} catch (exception& e) {
callback(string(e.what()));
}
}

void monero_wasm_bridge::create_keys_wallet_from_mnemonic(int network_type, const string& mnemonic, const string& seed_offset, emscripten::val callback) {
void monero_wasm_bridge::create_keys_wallet_from_seed(const string& config_json, emscripten::val callback) {
try {
monero_wallet* wallet = monero_wallet_keys::create_wallet_from_mnemonic(static_cast<monero_network_type>(network_type), mnemonic, seed_offset);
shared_ptr<monero_wallet_config> config = monero_wallet_config::deserialize(config_json);
config->m_path = std::string("");
monero_wallet* wallet = monero_wallet_keys::create_wallet_from_seed(*config);
callback((int) wallet); // callback with wallet memory address
} catch (exception& e) {
callback(string(e.what()));
}
}

void monero_wasm_bridge::create_keys_wallet_from_keys(int network_type, const string& address, const string& view_key, const string& spend_key, const string& language, emscripten::val callback) {
void monero_wasm_bridge::create_keys_wallet_from_keys(const string& config_json, emscripten::val callback) {
try {
monero_wallet* wallet = monero_wallet_keys::create_wallet_from_keys(static_cast<monero_network_type>(network_type), address, view_key, spend_key);
shared_ptr<monero_wallet_config> config = monero_wallet_config::deserialize(config_json);
config->m_path = std::string("");
monero_wallet* wallet = monero_wallet_keys::create_wallet_from_keys(*config);
callback((int) wallet); // callback with wallet memory address
} catch (exception& e) {
callback(string(e.what()));
}
}

string monero_wasm_bridge::get_keys_wallet_mnemonic_languages() {
string monero_wasm_bridge::get_keys_wallet_seed_languages() {
rapidjson::Document doc;
doc.SetObject();
doc.AddMember("languages", monero_utils::to_rapidjson_val(doc.GetAllocator(), monero_wallet_keys::get_mnemonic_languages()), doc.GetAllocator());
doc.AddMember("languages", monero_utils::to_rapidjson_val(doc.GetAllocator(), monero_wallet_keys::get_seed_languages()), doc.GetAllocator());
return monero_utils::serialize(doc);
}

Expand Down Expand Up @@ -274,18 +280,18 @@ string monero_wasm_bridge::get_version(int handle) {
return wallet->get_version().serialize();
}

string monero_wasm_bridge::get_mnemonic(int handle) {
string monero_wasm_bridge::get_seed(int handle) {
try {
monero_wallet* wallet = (monero_wallet*) handle;
return wallet->get_mnemonic();
return wallet->get_seed();
} catch (exception& e) {
return string("error: ") + string(e.what());
}
}

string monero_wasm_bridge::get_mnemonic_language(int handle) {
string monero_wasm_bridge::get_seed_language(int handle) {
monero_wallet* wallet = (monero_wallet*) handle;
return wallet->get_mnemonic_language();
return wallet->get_seed_language();
}

string monero_wasm_bridge::get_public_view_key(int handle) {
Expand Down
14 changes: 7 additions & 7 deletions src/main/cpp/monero_wasm_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ namespace monero_wasm_bridge

void open_wallet_full(const string& password, int network_type, const string& keys_data, const string& cache_data, const string& daemon_uri, const string& daemon_username, const string& daemon_password, const string& reject_unauthorized_fn_id, emscripten::val callback);
void create_full_wallet(const string& config_json, const string& reject_unauthorized_fn_id, emscripten::val callback);
string get_full_wallet_mnemonic_languages();
string get_full_wallet_seed_languages();

void create_keys_wallet_random(int network_type, const string& language, emscripten::val callback);
void create_keys_wallet_from_mnemonic(int network_type, const string& mnemonic, const string& seed_offset, emscripten::val callback);
void create_keys_wallet_from_keys(int network_type, const string& address, const string& view_key, const string& spend_key, const string& language, emscripten::val callback);
string get_keys_wallet_mnemonic_languages();
void create_keys_wallet_random(const string& config_json, emscripten::val callback);
void create_keys_wallet_from_seed(const string& config_json, emscripten::val callback);
void create_keys_wallet_from_keys(const string& config_json, emscripten::val callback);
string get_keys_wallet_seed_languages();

// ----------------------- WALLET INSTANCE METHODS --------------------------

Expand All @@ -49,8 +49,8 @@ namespace monero_wasm_bridge
void is_connected_to_daemon(int handle, emscripten::val callback);
void get_daemon_max_peer_height(int handle, emscripten::val callback);
string get_version(int handle);
string get_mnemonic(int handle);
string get_mnemonic_language(int handle);
string get_seed(int handle);
string get_seed_language(int handle);
string get_public_view_key(int handle);
string get_private_view_key(int handle);
string get_public_spend_key(int handle);
Expand Down
12 changes: 6 additions & 6 deletions src/main/js/common/MoneroWebWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,16 @@ self.getNetworkType = async function(walletId) {
// throw new Error("Not implemented");
//}

self.getMnemonic = async function(walletId) {
return self.WORKER_OBJECTS[walletId].getMnemonic();
self.getSeed = async function(walletId) {
return self.WORKER_OBJECTS[walletId].getSeed();
}

self.getMnemonicLanguage = async function(walletId) {
return self.WORKER_OBJECTS[walletId].getMnemonicLanguage();
self.getSeedLanguage = async function(walletId) {
return self.WORKER_OBJECTS[walletId].getSeedLanguage();
}

self.getMnemonicLanguages = async function(walletId) {
return self.WORKER_OBJECTS[walletId].getMnemonicLanguages();
self.getSeedLanguages = async function(walletId) {
return self.WORKER_OBJECTS[walletId].getSeedLanguages();
}

self.getPrivateSpendKey = async function(walletId) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/js/wallet/MoneroWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,20 @@ class MoneroWallet {
}

/**
* Get the wallet's mnemonic phrase derived from the seed.
* Get the wallet's mnemonic phrase or seed.
*
* @return {string} the wallet's mnemonic phrase
* @return {string} the wallet's mnemonic phrase or seed.
*/
async getMnemonic() {
async getSeed() {
throw new MoneroError("Not supported");
}

/**
* Get the language of the wallet's mnemonic phrase.
* Get the language of the wallet's mnemonic phrase or seed.
*
* @return {string} the language of the wallet's mnemonic phrase
* @return {string} the language of the wallet's mnemonic phrase or seed.
*/
async getMnemonicLanguage() {
async getSeedLanguage() {
throw new MoneroError("Not supported");
}

Expand Down
Loading

0 comments on commit b27f8bf

Please sign in to comment.