diff --git a/public/firefox.manifest.json b/public/firefox.manifest.json index d0152b955..4bb93244a 100644 --- a/public/firefox.manifest.json +++ b/public/firefox.manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Station Wallet", - "version": "7.2.4", + "version": "7.2.6", "background": { "scripts": ["background.js"], "persistent": true diff --git a/public/manifest.json b/public/manifest.json index a5bd5badd..1ac282abf 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Station Wallet", - "version": "7.2.4", + "version": "7.2.6", "background": { "service_worker": "background.js", "type": "module" diff --git a/scripts/contentScript.js b/scripts/contentScript.js index b93c1804f..043b8a0b4 100644 --- a/scripts/contentScript.js +++ b/scripts/contentScript.js @@ -76,8 +76,8 @@ function setupEvents() { if (namespace === "local") { if ( changes.wallet && - (Object.values(changes.wallet.oldValue.addresses).join(",") !== - Object.values(changes.wallet.newValue.addresses).join(",") || + (changes.wallet.oldValue.address !== changes.wallet.newValue.address || + changes.wallet.oldValue.name !== changes.wallet.newValue.name || Object.values(changes.wallet.oldValue.pubkey).join(",") !== Object.values(changes.wallet.newValue.pubkey).join(",")) ) { @@ -87,9 +87,17 @@ function setupEvents() { window.dispatchEvent(event) } if ( - changes.networks && - Object.keys(changes.networks.oldValue).join(",") !== - Object.keys(changes.networks.newValue).join(",") + changes.wallet && + changes.wallet.oldValue.theme !== changes.wallet.newValue.theme + ) { + const event = new CustomEvent("station_theme_change", { + detail: changes.wallet.newValue.theme, + }) + window.dispatchEvent(event) + } + if ( + changes.networkName && + changes.networkName.oldValue !== changes.networkName.newValue ) { const event = new CustomEvent("station_network_change", { detail: changes.networks.newValue, @@ -100,7 +108,9 @@ function setupEvents() { } extension.storage.local.get(["connect"], ({ connect }) => { - const isAllowed = ((connect && connect.allowed) || []).includes(window.location.origin) + const isAllowed = ((connect && connect.allowed) || []).includes( + window.location.origin + ) if (isAllowed) { extension.storage.onChanged.addListener(createEvent) diff --git a/src/auth/hooks/useAddress.ts b/src/auth/hooks/useAddress.ts index 97609ba81..78e80036e 100644 --- a/src/auth/hooks/useAddress.ts +++ b/src/auth/hooks/useAddress.ts @@ -2,7 +2,7 @@ import { useConnectedWallet } from "@terra-money/use-wallet" import { useNetworks } from "app/InitNetworks" import { addressFromWords } from "utils/bech32" import useAuth from "./useAuth" -import { useChainID } from "./useNetwork" +import { useChainID, useNetworkName } from "./useNetwork" import { useNetwork } from "data/wallet" /* auth | walle-provider */ @@ -17,9 +17,26 @@ const useAddress = () => { ? addressFromWords(wallet.words["330"]) : undefined } + export const useAllInterchainAddresses = () => { const connected = useConnectedWallet() + const { wallet } = useAuth() + const { networks } = useNetworks() + const networkName = useNetworkName() + if (connected?.addresses) return connected.addresses + + const words = wallet?.words + if (!words) return + + const addresses = Object.values(networks[networkName]).reduce( + (acc, { prefix, coinType, chainID }) => { + acc[chainID] = addressFromWords(words[coinType] as string, prefix) + return acc + }, + {} as Record + ) + return addresses } export const useInterchainAddresses = () => { diff --git a/src/auth/hooks/useAuth.ts b/src/auth/hooks/useAuth.ts index 2f65c95bc..bb5359484 100644 --- a/src/auth/hooks/useAuth.ts +++ b/src/auth/hooks/useAuth.ts @@ -132,8 +132,20 @@ const useAuth = () => { const { name, words } = getConnectedWallet() const key = getKey(password) if (!key) throw new PasswordError("Key do not exist") - // TODO: update key export - if ("seed" in key) throw new PasswordError("This key cannot be exported") + if ("seed" in key) { + const seed = new SeedKey({ + seed: Buffer.from(key.seed, "hex"), + coinType: key.legacy ? 118 : 330, + index: key.index || 0, + }) + + const data = { + name, + address: seed.accAddress("terra"), + encrypted_key: encrypt(seed.privateKey.toString("hex"), password), + } + return encode(JSON.stringify(data)) + } const data = { name, diff --git a/src/auth/modules/create/CreateWalletForm.tsx b/src/auth/modules/create/CreateWalletForm.tsx index 5d5e332ca..515aaa791 100644 --- a/src/auth/modules/create/CreateWalletForm.tsx +++ b/src/auth/modules/create/CreateWalletForm.tsx @@ -45,7 +45,6 @@ const CreateWalletForm = () => { form.trigger("confirm")} type="password" /> @@ -55,6 +54,7 @@ const CreateWalletForm = () => { {...register("confirm", { validate: (confirm) => validate.confirm(password, confirm), })} + onFocus={() => form.trigger("confirm")} type="password" /> diff --git a/src/auth/modules/manage/ChangePasswordForm.tsx b/src/auth/modules/manage/ChangePasswordForm.tsx index 39e95d361..b0f064064 100644 --- a/src/auth/modules/manage/ChangePasswordForm.tsx +++ b/src/auth/modules/manage/ChangePasswordForm.tsx @@ -64,6 +64,7 @@ const ChangePasswordForm = () => { {...register("confirm", { validate: (value) => validate.confirm(password, value), })} + onFocus={() => form.trigger("confirm")} type="password" /> diff --git a/src/auth/scripts/decrypt.ts b/src/auth/scripts/decrypt.ts index 8db4701ef..af5af73c9 100644 --- a/src/auth/scripts/decrypt.ts +++ b/src/auth/scripts/decrypt.ts @@ -4,25 +4,27 @@ const keySize = 256 const iterations = 100 const decrypt = (transitmessage: string, pass: string) => { - try { - const salt = CryptoJS.enc.Hex.parse(transitmessage.substr(0, 32)) - const iv = CryptoJS.enc.Hex.parse(transitmessage.substr(32, 32)) - const encrypted = transitmessage.substring(64) - - const key = CryptoJS.PBKDF2(pass, salt, { - keySize: keySize / 32, - iterations: iterations, - }) - - const decrypted = CryptoJS.AES.decrypt(encrypted, key, { - iv: iv, - padding: CryptoJS.pad.Pkcs7, - mode: CryptoJS.mode.CBC, - }).toString(CryptoJS.enc.Utf8) - return decrypted - } catch (error) { - return "" - } + const salt = CryptoJS.enc.Hex.parse(transitmessage.substring(0, 32)) + const iv = CryptoJS.enc.Hex.parse(transitmessage.substring(32, 64)) + const encrypted = transitmessage.substring(64) + + const key = CryptoJS.PBKDF2(pass, salt, { + keySize: keySize / 32, + iterations: iterations, + }) + + const decrypted = CryptoJS.AES.decrypt(encrypted, key, { + iv: iv, + padding: CryptoJS.pad.Pkcs7, + mode: CryptoJS.mode.CBC, + }) + + const decoded = decrypted.toString(CryptoJS.enc.Utf8) + + if (!decoded || decrypted.sigBytes < 128) + throw new Error("Incorrect password") + + return decoded } export default decrypt diff --git a/src/components/form/Input.tsx b/src/components/form/Input.tsx index c88104746..489d9d13c 100644 --- a/src/components/form/Input.tsx +++ b/src/components/form/Input.tsx @@ -47,6 +47,7 @@ const Input = forwardRef( {actionButton && (