Skip to content

Commit

Permalink
Fixed bug for wallets with spaces in the name
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Sanchez committed May 18, 2023
1 parent 1007b5c commit 99e174e
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 122 deletions.
3 changes: 3 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ build-extension-v2: build-extension

serve-extension:
cd extension && yarn run serve

upgrade-extension-patch:
cd extension/scripts && node upgradeVersion.js patch
2 changes: 1 addition & 1 deletion extension/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 16 additions & 10 deletions extension/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
[package]
name = "extension"
version = "0.1.0"
authors = ["The elenpay Developers"]
version = "0.2.3"
authors = [ "The elenpay Developers" ]
description = "A chrome extension/firefox add on for importing keys and signing PSBTs"
edition = "2021"

[lib]
crate-type = ["cdylib"]
crate-type = [ "cdylib" ]

[dependencies]
anyhow = "1.0.69"
signer = { path = "../signer" }
wasm-bindgen = { version="0.2.84" }
yew = { version = "0.20.0", features = ["csr"] }
yew-router = "0.17.0"
serde-wasm-bindgen = "0.5.0"
serde = "1.0.158"
js-sys = "0.3.61"
wasm-bindgen-futures = "0.4.34"

[dependencies.web-sys]
version = "0.3.61"
features = [
[dependencies.signer]
path = "../signer"

[dependencies.wasm-bindgen]
version = "0.2.84"

[dependencies.yew]
version = "0.20.0"
features = [ "csr" ]

[dependencies.web-sys]
version = "0.3.61"
features = [
"Document",
"Element",
"HtmlElement",
Expand All @@ -35,4 +42,3 @@ features = [
"HtmlSelectElement",
"Navigator"
]

1 change: 1 addition & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"release": "NODE_ENV=production yarn run build"
},
"devDependencies": {
"@iarna/toml": "^2.2.5",
"@types/chrome": "^0.0.124",
"@types/firefox-webext-browser": "^111.0.0",
"@wasm-tool/wasm-pack-plugin": "^1.3.1",
Expand Down
56 changes: 56 additions & 0 deletions extension/scripts/upgradeVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const manifest_v2 = require('../versions/manifest_v2.json');
const manifest_v3 = require('../static/manifest.json');
const TOML = require('@iarna/toml');
const fs = require('fs');

const cargo = TOML.parse(fs.readFileSync('../Cargo.toml', 'utf-8'));

const parseVersion = (version) => {
const [major, minor, patch] = version.split('.');
return {
major: parseInt(major),
minor: parseInt(minor),
patch: parseInt(patch),
};
};

const upgradeMajorVersion = (version) => {
const { major } = parseVersion(version);
return `${major + 1}.0.0`;
};

const upgradeMinorVersion = (version) => {
const { major, minor } = parseVersion(version);
return `${major}.${minor + 1}.0`;
};

const upgradePatchVersion = (version) => {
const { major, minor, patch } = parseVersion(version);
return `${major}.${minor}.${patch + 1}`;
};

const upgradeVersion = (version) => {
const args = process.argv.slice(2);
if (args.length === 0) {
throw new Error('Please specify the type of version upgrade');
}
const type = args[0];
switch (type) {
case 'major':
return upgradeMajorVersion(version);
case 'minor':
return upgradeMinorVersion(version);
case 'patch':
return upgradePatchVersion(version);
default:
return upgradePatchVersion(version);
}
};

manifest_v2.version = upgradeVersion(manifest_v2.version);
manifest_v3.version = upgradeVersion(manifest_v3.version);
cargo.package.version = upgradeVersion(cargo.package.version);

fs.writeFileSync('../versions/manifest_v2.json', JSON.stringify(manifest_v2, null, 2));
fs.writeFileSync('../static/manifest.json', JSON.stringify(manifest_v3, null, 2));
fs.writeFileSync('../Cargo.toml', TOML.stringify(cargo));
12 changes: 7 additions & 5 deletions extension/src/features/export_xpub.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{
components::text_input::TextInput,
context::UserContext,
utils::{helpers::get_clipboard, storage::LocalStorage},
utils::{
helpers::{decode_url_string, get_clipboard},
storage::LocalStorage,
},
};
use anyhow::Result;
use signer::storage::{SettingsStorage, UserStorage};
Expand All @@ -16,13 +19,14 @@ pub struct Props {

#[function_component(ExportXPUB)]
pub fn export_xpub(props: &Props) -> Html {
let decoded_wallet_name = decode_url_string(&props.wallet_name).unwrap();
let password = use_context::<UserContext>()
.unwrap()
.password
.clone()
.unwrap_or_default();
let mut storage = UserStorage::read(LocalStorage::default());
let wallet = storage.get_wallet_mut(&props.wallet_name);
let wallet = storage.get_wallet_mut(&decoded_wallet_name);
let navigator = use_navigator().unwrap();
let revealed_xpub = use_state(String::default);
let derivation = use_state(|| {
Expand All @@ -37,8 +41,6 @@ pub fn export_xpub(props: &Props) -> Html {
let next_derivation_value = (*next_derivation).clone();
let revealed_xpub_value = (*revealed_xpub).clone();
let error_value = (*error).clone();

let wallet_name = props.wallet_name.clone();
let password_value_ue = password.clone();
let next_derivation_value_ue = next_derivation_value.clone();
let revealed_xpub_ue = revealed_xpub.clone();
Expand All @@ -49,7 +51,7 @@ pub fn export_xpub(props: &Props) -> Html {
if !password_value_ue.is_empty() {
let mut storage = UserStorage::read(LocalStorage::default());
let settings = SettingsStorage::read(LocalStorage::default());
let wallet = storage.get_wallet_mut(&wallet_name);
let wallet = storage.get_wallet_mut(&decoded_wallet_name);
if let Some(w) = wallet {
let full_path = if next_derivation_value_ue.is_empty() {
w.derivation.to_string()
Expand Down
7 changes: 7 additions & 0 deletions extension/src/utils/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{anyhow, Context, Result};
use js_sys::decode_uri_component;
use wasm_bindgen::JsCast;
use web_sys::{window, Clipboard, HtmlElement};

Expand All @@ -23,3 +24,9 @@ pub fn get_clipboard() -> Result<Clipboard> {
.clipboard()
.context("No clipboard found")
}

pub fn decode_url_string(string: &str) -> Result<String> {
decode_uri_component(string)
.map_err(|_| anyhow!("Error while decoding url string"))
.map(|s| s.into())
}
116 changes: 58 additions & 58 deletions extension/static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
{
"manifest_version": 3,
"name": "NodeGuard Companion",
"description": "Import or generate your Bitcoin mnemonics, export your xpubs and sign your PSBTs with a few clicks. Your private keys never leave your browser, we don't store any data in our servers.",
"version": "0.2.2",
"action": {
"default_popup": "popup.html"
},
"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'"
},
"content_scripts": [
{
"matches": [
"http://localhost:38080/*",
"https://nodeguard-staging.elenpay.tech/*",
"https://nodeguard.elenpay.tech/*"
],
"js": [
"browser-polyfill.min.js",
"content.js"
]
}
],
"permissions": [
"activeTab",
"tabs",
"storage"
],
"web_accessible_resources": [
{
"resources": [
"index.js"
],
"matches": [
"http://localhost:38080/*",
"https://nodeguard-staging.elenpay.tech/*",
"https://nodeguard.elenpay.tech/*"
]
}
],
"externally_connectable": {
"matches": [
"http://localhost:38080/*",
"https://nodeguard-staging.elenpay.tech/*",
"https://nodeguard.elenpay.tech/*"
]
},
"icons": {
"16": "icon16.png",
"32": "icon32.png",
"48": "icon48.png",
"128": "icon128.png"
},
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "109.0"
}
"manifest_version": 3,
"name": "NodeGuard Companion",
"description": "Import or generate your Bitcoin mnemonics, export your xpubs and sign your PSBTs with a few clicks. Your private keys never leave your browser, we don't store any data in our servers.",
"version": "0.2.3",
"action": {
"default_popup": "popup.html"
},
"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'"
},
"content_scripts": [
{
"matches": [
"http://localhost:38080/*",
"https://nodeguard-staging.elenpay.tech/*",
"https://nodeguard.elenpay.tech/*"
],
"js": [
"browser-polyfill.min.js",
"content.js"
]
}
],
"permissions": [
"activeTab",
"tabs",
"storage"
],
"web_accessible_resources": [
{
"resources": [
"index.js"
],
"matches": [
"http://localhost:38080/*",
"https://nodeguard-staging.elenpay.tech/*",
"https://nodeguard.elenpay.tech/*"
]
}
],
"externally_connectable": {
"matches": [
"http://localhost:38080/*",
"https://nodeguard-staging.elenpay.tech/*",
"https://nodeguard.elenpay.tech/*"
]
},
"icons": {
"16": "icon16.png",
"32": "icon32.png",
"48": "icon48.png",
"128": "icon128.png"
},
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "109.0"
}
}
}
Loading

0 comments on commit 99e174e

Please sign in to comment.