diff --git a/.changeset/heavy-eggs-protect.md b/.changeset/heavy-eggs-protect.md new file mode 100644 index 000000000000..faf4f6760b13 --- /dev/null +++ b/.changeset/heavy-eggs-protect.md @@ -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 diff --git a/apps/ledger-live-desktop/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts b/apps/ledger-live-desktop/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts index d815533a74b9..d897437a2fd6 100644 --- a/apps/ledger-live-desktop/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts +++ b/apps/ledger-live-desktop/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts @@ -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 } = { diff --git a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts index 9560ea7f9b7f..df4d0137aa23 100644 --- a/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts +++ b/apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts @@ -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>(); function reset() { dispatch(resetTrustchainStore()); navigation.navigate(ScreenName.WalletSyncActivationInit); + sdk.invalidateJwt(); } const includesErrorActions: { [key: string]: () => void } = { diff --git a/libs/trustchain/src/mockSdk.ts b/libs/trustchain/src/mockSdk.ts index 00284506bed0..1e05b150b64d 100644 --- a/libs/trustchain/src/mockSdk.ts +++ b/libs/trustchain/src/mockSdk.ts @@ -238,4 +238,8 @@ export class MockSDK implements TrustchainSDK { assertTrustchain(trustchain); return Promise.resolve(applyXor(data)); } + + invalidateJwt(): void { + this.deviceJwtAcquired = false; + } } diff --git a/libs/trustchain/src/sdk.ts b/libs/trustchain/src/sdk.ts index 8c9668fb7174..7c9e4b35c651 100644 --- a/libs/trustchain/src/sdk.ts +++ b/libs/trustchain/src/sdk.ts @@ -314,6 +314,11 @@ export class SDK implements TrustchainSDK { ); } + invalidateJwt() { + this.jwt = undefined; + this.hwDeviceProvider.clearJwt(); + } + async destroyTrustchain( trustchain: Trustchain, memberCredentials: MemberCredentials, @@ -321,8 +326,7 @@ export class SDK implements TrustchainSDK { 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 { diff --git a/libs/trustchain/src/types.ts b/libs/trustchain/src/types.ts index 3f16e0e2fccf..9fb00f5cec10 100644 --- a/libs/trustchain/src/types.ts +++ b/libs/trustchain/src/types.ts @@ -226,6 +226,8 @@ export interface TrustchainSDK { * decrypt data with the trustchain encryption key */ decryptUserData(trustchain: Trustchain, data: Uint8Array): Promise; + + invalidateJwt(): void; } export interface TrustchainDeviceCallbacks {