diff --git a/DEV.md b/DEV.md index 168aeac..a5bd944 100644 --- a/DEV.md +++ b/DEV.md @@ -12,6 +12,11 @@ Until this [PR](https://github.com/rustwasm/wasm-pack/pull/1271) is accepted, wi cargo install wasm-pack --git https://github.com/rustwasm/wasm-pack.git --rev c2b663f25abe50631a236d57a8c6d7fd806413b2 ``` +On Debian distros +``` +sudo apt install pkg-config gcc build-essential libglib2.0-dev libgtk-3-dev libwebkit2gtk-4.1-dev +``` + ``` cargo install cargo-watch cargo install cargo-run-script diff --git a/nextgraph/examples/wallet-security-image-white.png b/nextgraph/examples/wallet-security-image-white.png new file mode 100644 index 0000000..dd7f476 Binary files /dev/null and b/nextgraph/examples/wallet-security-image-white.png differ diff --git a/nextgraph/src/lib.rs b/nextgraph/src/lib.rs index ef7beff..2052b25 100644 --- a/nextgraph/src/lib.rs +++ b/nextgraph/src/lib.rs @@ -127,7 +127,7 @@ pub fn get_device_name() -> String { } #[cfg(target_arch = "wasm32")] if let Ok(distro) = whoami::fallible::distro() { - list.push(distro); + list.push(distro.replace("Unknown ","")); } list.join(" ") diff --git a/nextgraph/src/local_broker.rs b/nextgraph/src/local_broker.rs index 82bab3b..005ae15 100644 --- a/nextgraph/src/local_broker.rs +++ b/nextgraph/src/local_broker.rs @@ -2864,6 +2864,20 @@ mod test { use std::io::Write; use std::path::Path; + #[async_std::test] + async fn output_image_for_test_white() { + let f = File::open("examples/wallet-security-image-white.png") + .expect("open of examples/wallet-security-image-white.png"); + let mut reader = BufReader::new(f); + let mut security_img = Vec::new(); + // Read file into vector. + reader + .read_to_end(&mut security_img) + .expect("read of valid_security_image.jpg"); + + log_info!("{:?}", security_img); + } + #[async_std::test] async fn gen_wallet_for_test() { if Path::new("tests/wallet.ngw").exists() { diff --git a/ng-sdk-js/DEV.md b/ng-sdk-js/DEV.md index bb37b52..9873d08 100644 --- a/ng-sdk-js/DEV.md +++ b/ng-sdk-js/DEV.md @@ -82,6 +82,15 @@ cargo run-script node cargo run-script web ``` +## Publishing to npm + +``` +cargo run-script node +cd pkg-node +npm login --auth-type legacy +npm publish --auth-type legacy +``` + ### Example Plain JS web app ``` diff --git a/ng-sdk-js/app-node/index.js b/ng-sdk-js/app-node/index.js index 73e21d5..79947cd 100644 --- a/ng-sdk-js/app-node/index.js +++ b/ng-sdk-js/app-node/index.js @@ -20,6 +20,9 @@ let buffer = fs.readFileSync("/Users/nl/Downloads/wallet-Hr-UITwGtjE1k6lXBoVGzD4 ng.wallet_read_file(buffer).then(async (wallet)=>{ console.log("start"); try { + //let wal = await ng.gen_wallet_for_test("rS6pZiroUZ5yjq9eraesDkpxWWOAoX_8QZ_5U9GXsOgA"); + //console.log(wal); + let opened_wallet = await ng.wallet_open_with_mnemonic_words(wallet, ["jealous", "during", "elevator", diff --git a/ng-sdk-js/prepare-node.js b/ng-sdk-js/prepare-node.js index 47b9eb7..1cdf4d5 100644 --- a/ng-sdk-js/prepare-node.js +++ b/ng-sdk-js/prepare-node.js @@ -6,7 +6,7 @@ const PATH_README = './pkg-node/README.md'; const pkg_json = fs.readFileSync(PATH); let pkg = JSON.parse(pkg_json) pkg.name = "nextgraph"; -pkg.version = "0.1.1-alpha.3"; +pkg.version = "0.1.1-alpha.4"; pkg.description = "nodeJS SDK of NextGraph"; pkg.files.push("ng_sdk_js_bg.wasm.d.ts"); pkg.files.push("snippets/**/*.js"); diff --git a/ng-sdk-js/src/lib.rs b/ng-sdk-js/src/lib.rs index d746660..d5df5dc 100644 --- a/ng-sdk-js/src/lib.rs +++ b/ng-sdk-js/src/lib.rs @@ -39,7 +39,7 @@ use ng_repo::utils::{decode_key, decode_priv_key}; use ng_net::app_protocol::*; use ng_net::broker::*; -use ng_net::types::{BindAddress, ClientInfo, ClientInfoV0, ClientType, CreateAccountBSP, IP}; +use ng_net::types::{BindAddress, ClientInfo, ClientInfoV0, ClientType, CreateAccountBSP, IP, BootstrapContentV0}; use ng_net::utils::{ decode_invitation_string, parse_ip_and_port_for, retrieve_local_bootstrap, retrieve_local_url, spawn_and_log_error, Receiver, ResultSend, Sender, @@ -55,6 +55,7 @@ use ng_wallet::*; use nextgraph::local_broker::*; use nextgraph::verifier::CancelFn; + use crate::model::*; #[wasm_bindgen] @@ -1953,6 +1954,45 @@ pub async fn user_connect( .unwrap()) } +const EMPTY_IMG: [u8;437] = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 150, 0, 0, 0, 150, 8, 6, 0, 0, 0, 60, 1, 113, 226, 0, 0, 0, 4, 103, 65, 77, 65, 0, 0, 177, 143, 11, 252, 97, 5, 0, 0, 0, 1, 115, 82, 71, 66, 1, 217, 201, 44, 127, 0, 0, 0, 32, 99, 72, 82, 77, 0, 0, 122, 38, 0, 0, 128, 132, 0, 0, 250, 0, 0, 0, 128, 232, 0, 0, 117, 48, 0, 0, 234, 96, 0, 0, 58, 152, 0, 0, 23, 112, 156, 186, 81, 60, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 3, 0, 0, 0, 3, 0, 1, 217, 203, 178, 96, 0, 0, 1, 30, 73, 68, 65, 84, 120, 218, 237, 210, 49, 17, 0, 0, 8, 196, 48, 192, 191, 231, 199, 0, 35, 99, 34, 161, 215, 78, 146, 130, 103, 35, 1, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 193, 109, 1, 34, 65, 5, 40, 46, 151, 166, 52, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130]; + +#[wasm_bindgen] +pub async fn gen_wallet_for_test(ngd_peer_id: String)-> Result { + init_local_broker_with_lazy(&INIT_LOCAL_BROKER).await; + //init_local_broker(Box::new(|| LocalBrokerConfig::InMemory)).await; + + let peer_id_of_server_broker = decode_key(&ngd_peer_id).map_err(|e: NgError| e.to_string())?; + + let wallet_result = wallet_create_v0(CreateWalletV0 { + security_img: Vec::from(EMPTY_IMG), + security_txt: "testsecurityphrase".to_string(), + pin: [1, 2, 1, 2], + pazzle_length: 9, + send_bootstrap: false, + send_wallet: false, + result_with_wallet_file: true, + local_save: false, + core_bootstrap: BootstrapContentV0::new_localhost(peer_id_of_server_broker), + core_registration: None, + additional_bootstrap: None, + pdf: false, + device_name: "test".to_string(), + }) + .await + .expect("wallet_create_v0"); + + let mut mnemonic_words = Vec::with_capacity(12); + display_mnemonic(&wallet_result.mnemonic) + .iter() + .for_each(|word| { + mnemonic_words.push(word.clone()); + }); + + let res = (serde_bytes::ByteBuf::from(wallet_result.wallet_file.clone()),mnemonic_words); + Ok(serde_wasm_bindgen::to_value(&res).unwrap()) + +} + #[cfg(test)] mod test { use wasm_bindgen_test::*;