Skip to content

Commit

Permalink
fix(trustchain): getOrCreateTrustchain wasn't working when another in…
Browse files Browse the repository at this point in the history
…stance destroyed the trustchain
  • Loading branch information
cgrellard-ledger committed Aug 20, 2024
1 parent 6fff337 commit 382abe8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
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

0 comments on commit 382abe8

Please sign in to comment.