|
| 1 | +import expect from 'expect'; |
| 2 | + |
| 3 | +import { |
| 4 | + createAndRegisterHardwareWalletChannels, |
| 5 | + createHardwareWalletConnectionChannel, |
| 6 | + initLedgerChannel, |
| 7 | + createTestInstructions, |
| 8 | + createCardanoAppChannel, |
| 9 | + createGetPublicKeyChannel, |
| 10 | + ipcRenderer, |
| 11 | +} from './utils'; |
| 12 | + |
| 13 | +export const run = () => { |
| 14 | + expect.assertions(3); |
| 15 | + |
| 16 | + createTestInstructions([ |
| 17 | + 'Plug Ledger Nano S to your computer', |
| 18 | + 'Launch Cardano APP on Nano S/Nano X', |
| 19 | + 'Run the test again with Cardano App opened', |
| 20 | + 'Export the public key', |
| 21 | + ]); |
| 22 | + |
| 23 | + createAndRegisterHardwareWalletChannels(); |
| 24 | + |
| 25 | + const cardanoAppChannel = createCardanoAppChannel(); |
| 26 | + const publicKeyChannel = createGetPublicKeyChannel(); |
| 27 | + const hardwareWalletConnectionChannel = |
| 28 | + createHardwareWalletConnectionChannel(); |
| 29 | + |
| 30 | + return new Promise<void>((resolve) => { |
| 31 | + hardwareWalletConnectionChannel.onReceive( |
| 32 | + async (params: { path: string }) => { |
| 33 | + expect(params).toEqual({ |
| 34 | + disconnected: expect.any(Boolean), |
| 35 | + deviceType: expect.any(String), |
| 36 | + deviceId: null, |
| 37 | + deviceModel: expect.any(String), |
| 38 | + deviceName: expect.any(String), |
| 39 | + path: expect.any(String), |
| 40 | + product: expect.any(String), |
| 41 | + }); |
| 42 | + |
| 43 | + const cardanoAppChannelReply = await cardanoAppChannel.request( |
| 44 | + { path: params.path }, |
| 45 | + ipcRenderer, |
| 46 | + ipcRenderer |
| 47 | + ); |
| 48 | + |
| 49 | + expect(cardanoAppChannelReply).toEqual({ |
| 50 | + minor: expect.any(Number), |
| 51 | + major: expect.any(Number), |
| 52 | + patch: expect.any(Number), |
| 53 | + deviceId: expect.any(String), |
| 54 | + }); |
| 55 | + |
| 56 | + const extendedPublicKey = await publicKeyChannel.request( |
| 57 | + { |
| 58 | + path: "1852'/1815'/0'", |
| 59 | + // Shelley 1852 ADA 1815 indicator for account '0' |
| 60 | + isTrezor: false, |
| 61 | + devicePath: params.path, |
| 62 | + }, |
| 63 | + ipcRenderer, |
| 64 | + ipcRenderer |
| 65 | + ); |
| 66 | + |
| 67 | + expect(extendedPublicKey).toEqual({ |
| 68 | + chainCodeHex: expect.any(String), |
| 69 | + publicKeyHex: expect.any(String), |
| 70 | + deviceId: expect.any(String), |
| 71 | + }); |
| 72 | + |
| 73 | + resolve(); |
| 74 | + } |
| 75 | + ); |
| 76 | + |
| 77 | + initLedgerChannel(); |
| 78 | + }); |
| 79 | +}; |
0 commit comments