Skip to content

Commit

Permalink
fix(connect): keepSession with changing useCardanoDerivation
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan authored and mroz22 committed Sep 19, 2024
1 parent aa04ab3 commit 8c654a1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
42 changes: 42 additions & 0 deletions packages/connect/e2e/tests/device/keepSession.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import TrezorConnect from '../../../src';

import { getController, setup, conditionalTest, initTrezorConnect } from '../../common.setup';

const controller = getController();

describe('keepSession common param', () => {
beforeAll(async () => {
await TrezorConnect.dispose();
await setup(controller, {
mnemonic: 'mnemonic_all',
});
await initTrezorConnect(controller);
});

afterAll(async () => {
controller.dispose();
await TrezorConnect.dispose();
});

conditionalTest(['1', '<2.3.2'], 'keepSession with changing useCardanoDerivation', async () => {
const noDerivation = await TrezorConnect.getAccountDescriptor({
coin: 'ada',
path: "m/1852'/1815'/0'/0/0",
useCardanoDerivation: false,
keepSession: true,
});
if (noDerivation.success) throw new Error('noDerivation should not succeed');
expect(noDerivation.payload.error).toBe(
'Cardano derivation is not enabled for this session',
);

const enableDerivation = await TrezorConnect.getAccountDescriptor({
coin: 'ada',
path: "m/1852'/1815'/0'/0/0",
useCardanoDerivation: true,
keepSession: true,
});
if (!enableDerivation.success) throw new Error(enableDerivation.payload.error);
expect(enableDerivation.payload.descriptor).toBeDefined();
});
});
10 changes: 9 additions & 1 deletion packages/connect/src/device/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export class Device extends TypedEmitter<DeviceEvents> {
firmwareRevision: null,
};

private useCardanoDerivation = false;

constructor(transport: Transport, descriptor: Descriptor) {
super();

Expand Down Expand Up @@ -331,7 +333,12 @@ export class Device extends TypedEmitter<DeviceEvents> {
await this.releasePromise;
}

if (!this.isUsedHere() || this.commands?.disposed || !this.getState()?.staticSessionId) {
if (
!this.isUsedHere() ||
this.commands?.disposed ||
!this.getState()?.staticSessionId ||
this.useCardanoDerivation != !!options.useCardanoDerivation
) {
// acquire session
await this.acquire();

Expand Down Expand Up @@ -516,6 +523,7 @@ export class Device extends TypedEmitter<DeviceEvents> {
// If the user has BIP-39 seed, and Initialize(derive_cardano=True) is not sent,
// all Cardano calls will fail because the root secret will not be available.
payload.derive_cardano = useCardanoDerivation;
this.useCardanoDerivation = useCardanoDerivation;
if (sessionId) {
payload.session_id = sessionId;
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/connect-test-matrix-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const groups = {
api: {
name: 'api',
pattern:
'init authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy override checkFirmwareAuthenticity',
'init authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy override checkFirmwareAuthenticity keepSession',
methods: '',
},
management: {
Expand Down

0 comments on commit 8c654a1

Please sign in to comment.