Skip to content
Open
13 changes: 12 additions & 1 deletion ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
/* Begin PBXFileReference section */
1A6B2865F76F213517CFCCD1 /* AppViewController.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AppViewController.swift; sourceTree = "<group>"; };
21A34DAD709C71D553F88951 /* LocalBiometricPlugin.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = LocalBiometricPlugin.swift; sourceTree = "<group>"; };
C7D4E92B3F8B1C5D00A2B9E2 /* BarcodeScannerPlugin.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = BarcodeScannerPlugin.swift; sourceTree = "<group>"; };
2FAD9762203C412B000D30F8 /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = config.xml; sourceTree = "<group>"; };
50379B222058CBB4000EE86E /* capacitor.config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = capacitor.config.json; sourceTree = "<group>"; };
504EC3041FED79650016851F /* App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -36,6 +35,7 @@
873F0344C8952CB5585102E0 /* App.entitlements */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.entitlements; path = App.entitlements; sourceTree = "<group>"; };
958DCC722DB07C7200EA8C5F /* debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = debug.xcconfig; path = ../debug.xcconfig; sourceTree = SOURCE_ROOT; };
BFB20C26958B0AB36D108D0E /* Pods-App.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.release.xcconfig"; path = "Target Support Files/Pods-App/Pods-App.release.xcconfig"; sourceTree = "<group>"; };
C7D4E92B3F8B1C5D00A2B9E2 /* BarcodeScannerPlugin.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = BarcodeScannerPlugin.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -56,6 +56,7 @@
958DCC722DB07C7200EA8C5F /* debug.xcconfig */,
504EC3061FED79650016851F /* App */,
504EC3051FED79650016851F /* Products */,
7BF04FDF2F1F799A005E306E /* Recovered References */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -86,6 +87,14 @@
path = App;
sourceTree = "<group>";
};
7BF04FDF2F1F799A005E306E /* Recovered References */ = {
isa = PBXGroup;
children = (
BFB20C26958B0AB36D108D0E /* Pods-App.release.xcconfig */,
);
name = "Recovered References";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -313,6 +322,7 @@
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = YQ9XQQJ5ZM;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -337,6 +347,7 @@
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = YQ9XQQJ5ZM;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down

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

16 changes: 13 additions & 3 deletions src/app/pages/ForgotPassword/ForgotPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { formatMnemonic } from 'app/defaults';
import { useMidenContext } from 'lib/miden/front';
import { clearClientStorage } from 'lib/miden/reset';
import { useMobileBackHandler } from 'lib/mobile/useMobileBackHandler';
import type { WalletAccount } from 'lib/shared/types';
import { navigate } from 'lib/woozie';
import { ForgotPasswordFlow } from 'screens/onboarding/forgot-password-navigator';
import { ForgotPasswordAction, ForgotPasswordStep, OnboardingType } from 'screens/onboarding/types';
Expand All @@ -18,6 +19,7 @@ const ForgotPassword: FC = () => {
const [password, setPassword] = useState<string | null>(null);
const [importedWithFile, setImportedWithFile] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [importedWalletAccounts, setImportedWalletAccounts] = useState<WalletAccount[]>([]);

const { registerWallet, importWalletFromClient } = useMidenContext();

Expand All @@ -39,13 +41,21 @@ const ForgotPassword: FC = () => {
} else {
try {
console.log('importing wallet from client');
await importWalletFromClient(password, seedPhraseFormatted);
await importWalletFromClient(password, seedPhraseFormatted, importedWalletAccounts);
} catch (e) {
console.error(e);
}
}
}
}, [password, seedPhrase, importedWithFile, registerWallet, onboardingType, importWalletFromClient]);
}, [
password,
seedPhrase,
importedWithFile,
registerWallet,
onboardingType,
importWalletFromClient,
importedWalletAccounts
]);

const onAction = useCallback(
async (action: ForgotPasswordAction) => {
Expand All @@ -64,8 +74,8 @@ const ForgotPassword: FC = () => {
break;
case 'import-wallet-file-submit':
const seedPhrase = action.payload.split(' ');
console.log({ seedPhrase });
setSeedPhrase(seedPhrase);
setImportedWalletAccounts(action.walletAccounts);
setImportedWithFile(true);
setStep(ForgotPasswordStep.CreatePassword);
break;
Expand Down
22 changes: 18 additions & 4 deletions src/app/pages/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AnalyticsEventCategory, useAnalytics } from 'lib/analytics';
import { useMidenContext } from 'lib/miden/front';
import { useMobileBackHandler } from 'lib/mobile/useMobileBackHandler';
import { isDesktop, isMobile } from 'lib/platform';
import { WalletStatus } from 'lib/shared/types';
import { WalletStatus, WalletAccount } from 'lib/shared/types';
import { useWalletStore } from 'lib/store';
import { fetchStateFromBackend } from 'lib/store/hooks/useIntercomSync';
import { navigate, useLocation } from 'lib/woozie';
Expand Down Expand Up @@ -77,6 +77,7 @@ const Welcome: FC = () => {
const [isHardwareSecurityAvailable, setIsHardwareSecurityAvailable] = useState(false);
const [biometricAttempts, setBiometricAttempts] = useState(0);
const [biometricError, setBiometricError] = useState<string | null>(null);
const [importedWalletAccounts, setImportedWalletAccounts] = useState<WalletAccount[]>([]);
const { registerWallet, importWalletFromClient } = useMidenContext();
const { trackEvent } = useAnalytics();
const syncFromBackend = useWalletStore(s => s.syncFromBackend);
Expand All @@ -96,12 +97,25 @@ const Welcome: FC = () => {
if (!importedWithFile) {
await registerWallet(actualPassword, seedPhraseFormatted, onboardingType === OnboardingType.Import);
} else {
await importWalletFromClient(actualPassword, seedPhraseFormatted);
try {
console.log('importing wallet from client');
await importWalletFromClient(actualPassword, seedPhraseFormatted, importedWalletAccounts);
} catch (e) {
console.error(e);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should show an error message, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No UI for this currently; do you want me to address it in this one or separate one

}
}
} else {
throw new Error('Missing password or seed phrase');
}
}, [password, seedPhrase, importedWithFile, registerWallet, onboardingType, importWalletFromClient]);
}, [
password,
seedPhrase,
importedWithFile,
registerWallet,
onboardingType,
importWalletFromClient,
importedWalletAccounts
]);

const onAction = async (action: OnboardingAction) => {
let eventCategory = AnalyticsEventCategory.ButtonPress;
Expand All @@ -123,8 +137,8 @@ const Welcome: FC = () => {
break;
case 'import-wallet-file-submit':
const seedPhrase = action.payload.split(' ');
console.log({ seedPhrase });
setSeedPhrase(seedPhrase);
setImportedWalletAccounts(action.walletAccounts);
setImportedWithFile(true);
// Check if hardware security is available - if so, skip password step
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/intercom/desktop-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class DesktopIntercomAdapter {
return { type: WalletMessageType.NewWalletResponse };

case WalletMessageType.ImportFromClientRequest:
await Actions.registerImportedWallet((req as any).password, (req as any).mnemonic);
await Actions.registerImportedWallet(req.password, req.mnemonic, req.walletAccounts);
return { type: WalletMessageType.ImportFromClientResponse };

case WalletMessageType.UnlockRequest:
Expand Down
7 changes: 4 additions & 3 deletions src/lib/intercom/mobile-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ describe('MobileIntercomAdapter', () => {
const response = await adapter.request({
type: WalletMessageType.ImportFromClientRequest,
password: 'test123',
mnemonic: 'word1 word2 word3'
} as any);
mnemonic: 'word1 word2 word3',
walletAccounts: []
});

expect(Actions.registerImportedWallet).toHaveBeenCalledWith('test123', 'word1 word2 word3');
expect(Actions.registerImportedWallet).toHaveBeenCalledWith('test123', 'word1 word2 word3', []);
expect(response).toEqual({ type: WalletMessageType.ImportFromClientResponse });
});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/intercom/mobile-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class MobileIntercomAdapter {
return { type: WalletMessageType.NewWalletResponse };

case WalletMessageType.ImportFromClientRequest:
await Actions.registerImportedWallet((req as any).password, (req as any).mnemonic);
await Actions.registerImportedWallet(req.password, req.mnemonic, req.walletAccounts);
return { type: WalletMessageType.ImportFromClientResponse };

case WalletMessageType.UnlockRequest:
Expand Down
5 changes: 3 additions & 2 deletions src/lib/miden/back/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,12 @@ describe('actions', () => {
};
Vault.spawnFromMidenClient.mockResolvedValueOnce(mockVaultInstance);

await registerImportedWallet('password123', 'mnemonic words');
await registerImportedWallet('password123', 'mnemonic words', []);

expect(Vault.spawnFromMidenClient).toHaveBeenCalledWith('password123', 'mnemonic words');
expect(mockVaultInstance.fetchAccounts).toHaveBeenCalled();
expect(mockUnlocked).toHaveBeenCalled();
expect(Vault.spawnFromMidenClient).toHaveBeenCalledWith('password123', 'mnemonic words', []);
expect(Vault.setup).toHaveBeenCalledWith('password123');
});
});

Expand Down
12 changes: 8 additions & 4 deletions src/lib/miden/back/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from 'lib/miden/back/store';
import { Vault } from 'lib/miden/back/vault';
import { getStorageProvider } from 'lib/platform/storage-adapter';
import { WalletSettings, WalletState } from 'lib/shared/types';
import { WalletAccount, WalletSettings, WalletState } from 'lib/shared/types';
import { WalletType } from 'screens/onboarding/types';

import { MidenSharedStorageKey } from '../types';
Expand Down Expand Up @@ -90,11 +90,15 @@ export function registerNewWallet(password?: string, mnemonic?: string, ownMnemo
});
}

export function registerImportedWallet(password?: string, mnemonic?: string) {
export function registerImportedWallet(
password: string | undefined,
mnemonic: string,
walletAccounts: WalletAccount[]
) {
return withInited(async () => {
// Password may be undefined for hardware-only wallets
// spawnFromMidenClient() returns the vault directly, avoiding a second biometric prompt
const vault = await Vault.spawnFromMidenClient(password ?? '', mnemonic ?? '');
const vault = await Vault.spawnFromMidenClient(password ?? '', mnemonic, walletAccounts);
const accounts = await vault.fetchAccounts();
const settings = await vault.fetchSettings();
const currentAccount = await vault.getCurrentAccount();
Expand Down Expand Up @@ -154,7 +158,7 @@ export function decryptCiphertexts(accPublicKey: string, cipherTexts: string[])

export function revealViewKey(accPublicKey: string, password: string) {}

export function revealMnemonic(password: string) {
export function revealMnemonic(password: string | undefined) {
return withUnlocked(() => Vault.revealMnemonic(password));
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/miden/back/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function processRequest(req: WalletRequest, port: Runtime.Port): Promise<W
await Actions.registerNewWallet(req.password, req.mnemonic, req.ownMnemonic);
return { type: WalletMessageType.NewWalletResponse };
case WalletMessageType.ImportFromClientRequest:
await Actions.registerImportedWallet(req.password, req.mnemonic);
await Actions.registerImportedWallet(req.password, req.mnemonic, req.walletAccounts);
return { type: WalletMessageType.ImportFromClientResponse };
case WalletMessageType.UnlockRequest:
await Actions.unlock(req.password);
Expand Down
Loading
Loading