From e46fee459d8154c70beb6ca594808dc5d6a6240a Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Mon, 2 Jun 2025 15:18:38 -0700 Subject: [PATCH] Allow pin change while in duress mode for non-duress account --- CHANGELOG.md | 2 ++ src/core/login/pin2.ts | 8 ++++---- test/core/login/login.test.ts | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f242f5b0..8e234729 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- fixed: Allow pin change while device is in duress mode and user is logged into a non-duress account. + ## 2.30.2 (2025-05-30) - fixed: Create a package.json React Native export. diff --git a/src/core/login/pin2.ts b/src/core/login/pin2.ts index 2fe0c150..00c347e2 100644 --- a/src/core/login/pin2.ts +++ b/src/core/login/pin2.ts @@ -80,7 +80,7 @@ export async function changePin( opts: ChangePinOptions ): Promise { const accountState = ai.props.state.accounts[accountId] - const inDuressMode = ai.props.state.clientInfo.duressEnabled + const isDuressAccount = accountState.activeAppId.endsWith('.duress') const { loginTree, login, sessionKey } = accountState const { username } = accountState.stashTree @@ -95,7 +95,7 @@ export async function changePin( // Deleting PIN logins while in duress account should delete PIN locally for // all nodes: - if (inDuressMode && !forDuressAccount) { + if (isDuressAccount && !forDuressAccount) { if (enableLogin) { if (pin != null) { await applyKits( @@ -128,7 +128,7 @@ export async function changePin( await applyKits( ai, sessionKey, - makeDeletePin2Kits(loginTree, forDuressAccount || inDuressMode) + makeDeletePin2Kits(loginTree, forDuressAccount || isDuressAccount) ) return } @@ -139,7 +139,7 @@ export async function changePin( username, pin, enableLogin, - forDuressAccount || inDuressMode + forDuressAccount || isDuressAccount ) await applyKits(ai, sessionKey, kits) } diff --git a/test/core/login/login.test.ts b/test/core/login/login.test.ts index ca032f8b..b5ee0fa4 100644 --- a/test/core/login/login.test.ts +++ b/test/core/login/login.test.ts @@ -491,6 +491,31 @@ describe('pin', function () { }) }) + it('can change pin while device is in duress-mode', async function () { + const world = await makeFakeEdgeWorld([fakeUser], quiet) + const context = await world.makeEdgeContext(contextOptions) + await ( + await context.createAccount({ + username: 'other-account', + pin: '1111' + }) + ).logout() + + const account = await context.loginWithPIN(fakeUser.username, fakeUser.pin) + await account.changePin({ pin: '0000', forDuressAccount: true }) + await account.logout() + + // Enable duress mode: + const duressAccount = await context.loginWithPIN(fakeUser.username, '0000') + await duressAccount.logout() + + const otherAccount = await context.loginWithPIN('other-account', '1111') + await otherAccount.changePin({ pin: '1234' }) + await otherAccount.logout() + + await context.loginWithPIN('other-account', '1234') + }) + it('pin-login remains enabled for accounts without duress mode setup after duress mode login', async function () { const world = await makeFakeEdgeWorld([fakeUser], quiet) const context = await world.makeEdgeContext(contextOptions)