diff --git a/.vscode/settings.json b/.vscode/settings.json index 4e05f85..f5a7cba 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,16 +5,19 @@ "Authorise", "Inequal", "KRISTWALLET", + "KRISTWALLETEXTENSION", "Lngs", "Sider", "Syncable", "Transpiler", "antd", "anticon", + "appendhashes", "arraybuffer", "authorised", "clientside", "dont", + "jwalelset", "languagedetector", "localisation", "multiline", diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index b4fc496..0022610 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -132,6 +132,8 @@ "walletCategoryDropdownNewPlaceholder": "Category name", "walletAddress": "Wallet address", + "walletUsername": "Wallet username", + "walletUsernamePlaceholder": "Wallet username", "walletPassword": "Wallet password", "walletPasswordPlaceholder": "Wallet password", "walletPasswordWarning": "Make sure to save this somewhere <1>secure!", @@ -143,6 +145,8 @@ "walletFormat": "Wallet format", "walletFormatKristWallet": "KristWallet, KWallet (recommended)", + "walletFormatKristWalletUsernameAppendhashes": "KW-Username (appendhashes)", + "walletFormatKristWalletUsername": "KW-Username (pre-appendhashes)", "walletFormatApi": "Raw/API (advanced users)", "walletSave": "Save this wallet in KristWeb" diff --git a/src/krist/wallets/formats/WalletFormat.ts b/src/krist/wallets/formats/WalletFormat.ts index 0622b3c..d9c2389 100644 --- a/src/krist/wallets/formats/WalletFormat.ts +++ b/src/krist/wallets/formats/WalletFormat.ts @@ -4,18 +4,26 @@ (password: string, username?: string): Promise; } -export const KristWalletFormat: WalletFormat - = async password => await sha256("KRISTWALLET" + password) + "-000"; +export type WalletFormatName = "kristwallet" | "kristwallet_username_appendhashes" | "kristwallet_username" | "jwalelset" | "api"; +export const WALLET_FORMATS: Record = { + "kristwallet": async password => + await sha256("KRISTWALLET" + password) + "-000", -export const APIFormat: WalletFormat - = async password => password; + "kristwallet_username_appendhashes": async (password, username) => + await sha256("KRISTWALLETEXTENSION" + await sha256(await sha256(username || "") + "^" + await sha256(password))) + "-000", -export type WalletFormatName = "kristwallet" | "api"; -export const WalletFormatMap: Record = { - "kristwallet": KristWalletFormat, - "api": APIFormat + "kristwallet_username": async (password, username) => + await sha256(await sha256(username || "") + "^" + await sha256(password)), + + "jwalelset": async password => + await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(await sha256(password)))))))))))))))))), + + "api": async password => password }; export const applyWalletFormat = - (format: WalletFormatName, password: string): Promise => - WalletFormatMap[format](password); + (format: WalletFormatName, password: string, username?: string): Promise => + WALLET_FORMATS[format](password, username); + +export const formatNeedsUsername = (format: WalletFormatName): boolean => + WALLET_FORMATS[format].length === 2; diff --git a/src/pages/wallets/AddWalletModal.tsx b/src/pages/wallets/AddWalletModal.tsx index 581856c..cf1f20b 100644 --- a/src/pages/wallets/AddWalletModal.tsx +++ b/src/pages/wallets/AddWalletModal.tsx @@ -9,7 +9,7 @@ import { FakeUsernameInput } from "../../components/auth/FakeUsernameInput"; import { CopyInputButton } from "../../components/CopyInputButton"; import { getWalletCategoryDropdown } from "../../components/wallets/WalletCategoryDropdown"; -import { WalletFormatName, applyWalletFormat } from "../../krist/wallets/formats/WalletFormat"; +import { WalletFormatName, applyWalletFormat, formatNeedsUsername } from "../../krist/wallets/formats/WalletFormat"; import { makeV2Address } from "../../krist/AddressAlgo"; const { Text } = Typography; @@ -18,6 +18,7 @@ label?: string; category: string; + walletUsername: string; password: string; format: WalletFormatName; @@ -49,13 +50,13 @@ function onValuesChange(changed: Partial, values: Partial) { if (changed.format) setFormatState(changed.format); - if ((changed.format || changed.password) && values.password) - updateCalculatedAddress(values.format, values.password); + if ((changed.format || changed.password || changed.walletUsername) && values.password) + updateCalculatedAddress(values.format, values.password, values.walletUsername); } /** Update the 'Wallet address' field */ - async function updateCalculatedAddress(format: WalletFormatName | undefined, password: string) { - const privatekey = await applyWalletFormat(format || "kristwallet", password); + async function updateCalculatedAddress(format: WalletFormatName | undefined, password: string, username?: string) { + const privatekey = await applyWalletFormat(format || "kristwallet", password, username); const address = await makeV2Address(privatekey); setCalculatedAddress(address); } @@ -120,10 +121,16 @@ - {/* Fake username input to trick browser autofill */} + {/* Wallet username, if applicable */} + {formatState && formatNeedsUsername(formatState) && ( + + + + )} + {/* Wallet password */}