Skip to content

Commit

Permalink
Add seed phrase to same origin as devices (#2818)
Browse files Browse the repository at this point in the history
* Add seed phrase to same origin as devices

* Add flag
  • Loading branch information
lmuntaner authored Jan 24, 2025
1 parent 0852c8b commit 6819061
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
12 changes: 11 additions & 1 deletion src/frontend/src/flows/manage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,17 @@ export const displayManage = async (
return;
}
doAdd satisfies "ok";
await setupPhrase(userNumber, connection);
const newDeviceOrigin = DOMAIN_COMPATIBILITY.isEnabled()
? getCredentialsOrigin({
credentials: devices_,
userAgent: window.navigator.userAgent,
})
: undefined;
await setupPhrase(
userNumber,
connection,
newDeviceOrigin ?? window.origin
);
resolve();
};

Expand Down
30 changes: 3 additions & 27 deletions src/frontend/src/flows/recovery/setupRecovery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DeviceData } from "$generated/internet_identity_types";
import { displayError } from "$src/components/displayError";
import { withLoader } from "$src/components/loader";
import { fromMnemonicWithoutValidation } from "$src/crypto/ed25519";
import { generate } from "$src/crypto/mnemonic";
Expand All @@ -17,30 +16,6 @@ import { nonNullish } from "@dfinity/utils";
import { confirmSeedPhrase } from "./confirmSeedPhrase";
import { displaySeedPhrase } from "./displaySeedPhrase";

export const setupRecovery = async ({
userNumber,
connection,
}: {
userNumber: bigint;
connection: AuthenticatedConnection;
}): Promise<void> => {
// Retry until user explicitly cancels or until a phrase is added successfully
for (;;) {
const res = await setupPhrase(userNumber, connection);
if (res === "ok" || res === "canceled") {
return;
}

res satisfies "error";
await displayError({
title: "Failed to set up recovery",
message: "We failed to set up recovery for this Internet Identity.",
primaryButton: "Retry",
});
continue;
}
};

// Set up a recovery device
export const setupKey = async ({
devices: devices_,
Expand Down Expand Up @@ -90,7 +65,8 @@ export const setupKey = async ({
// Set up a recovery phrase
export const setupPhrase = async (
userNumber: bigint,
connection: AuthenticatedConnection
connection: AuthenticatedConnection,
origin: string
): Promise<"ok" | "error" | "canceled"> => {
const res = await phraseWizard({
userNumber,
Expand All @@ -103,7 +79,7 @@ export const setupPhrase = async (
{ recovery: null },
pubkey,
{ unprotected: null },
window.origin
origin
)
),
});
Expand Down

0 comments on commit 6819061

Please sign in to comment.