Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ledger Sync - Fixed the getOrCreateTrustchain when another instance deleted the trustchain #7632

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/heavy-eggs-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/trustchain": patch
---

LLM / LLD - Fix the getOrCreateTrustchain that wasn't working when another instance destroyed the trustchain
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import {
TrustchainOutdated,
} from "@ledgerhq/trustchain/errors";
import { useRestoreTrustchain } from "./useRestoreTrustchain";
import { useTrustchainSdk } from "./useTrustchainSdk";

export const useLifeCycle = () => {
const dispatch = useDispatch();
const sdk = useTrustchainSdk();

const { refetch: restoreTrustchain } = useRestoreTrustchain();

function reset() {
dispatch(resetTrustchainStore());
dispatch(setFlow({ flow: Flow.Activation, step: Step.CreateOrSynchronize }));
sdk.invalidateJwt();
}

const includesErrorActions: { [key: string]: () => void } = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import { useNavigation } from "@react-navigation/native";
import { StackNavigatorNavigation } from "~/components/RootNavigator/types/helpers";
import { WalletSyncNavigatorStackParamList } from "~/components/RootNavigator/types/WalletSyncNavigator";
import { ScreenName } from "~/const";
import { useTrustchainSdk } from "./useTrustchainSdk";

export const useLifeCycle = () => {
const dispatch = useDispatch();
const sdk = useTrustchainSdk();

const navigation = useNavigation<StackNavigatorNavigation<WalletSyncNavigatorStackParamList>>();

function reset() {
dispatch(resetTrustchainStore());
navigation.navigate(ScreenName.WalletSyncActivationInit);
sdk.invalidateJwt();
}

const includesErrorActions: { [key: string]: () => void } = {
Expand Down
4 changes: 4 additions & 0 deletions libs/trustchain/src/mockSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,8 @@ export class MockSDK implements TrustchainSDK {
assertTrustchain(trustchain);
return Promise.resolve(applyXor(data));
}

invalidateJwt(): void {
this.deviceJwtAcquired = false;
}
}
8 changes: 6 additions & 2 deletions libs/trustchain/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,19 @@ export class SDK implements TrustchainSDK {
);
}

invalidateJwt() {
this.jwt = undefined;
this.hwDeviceProvider.clearJwt();
}

async destroyTrustchain(
trustchain: Trustchain,
memberCredentials: MemberCredentials,
): Promise<void> {
await this.withAuth(trustchain, memberCredentials, jwt =>
this.api.deleteTrustchain(jwt, trustchain.rootId),
);
this.jwt = undefined;
this.hwDeviceProvider.clearJwt();
this.invalidateJwt();
}

async encryptUserData(trustchain: Trustchain, input: Uint8Array): Promise<Uint8Array> {
Expand Down
2 changes: 2 additions & 0 deletions libs/trustchain/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ export interface TrustchainSDK {
* decrypt data with the trustchain encryption key
*/
decryptUserData(trustchain: Trustchain, data: Uint8Array): Promise<Uint8Array>;

invalidateJwt(): void;
}

export interface TrustchainDeviceCallbacks {
Expand Down
Loading