1- import { Ledger , LedgerSigner } from './ledger'
1+ import { DerivationPathTypeLegacy , DerivationPathTypeAdr8 , Ledger , LedgerSigner } from './ledger'
22import OasisApp from '@oasisprotocol/ledger'
33import { WalletError , WalletErrors } from 'types/errors'
44import { Wallet , WalletType } from 'app/state/wallet/types'
@@ -18,29 +18,46 @@ describe('Ledger Library', () => {
1818 describe ( 'Ledger' , ( ) => {
1919 it ( 'enumerateAccounts should pass when Oasis App is open' , async ( ) => {
2020 mockAppIsOpen ( 'Oasis' )
21- const accounts = Ledger . enumerateAccounts ( { } as any , 0 )
21+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy , 0 )
22+ await expect ( accounts ) . resolves . toEqual ( [ ] )
23+ } )
24+ it ( 'enumerateAccounts should pass when Oasis App is open' , async ( ) => {
25+ mockAppIsOpen ( 'Oasis' )
26+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeAdr8 , 0 )
2227 await expect ( accounts ) . resolves . toEqual ( [ ] )
2328 } )
2429
2530 it ( 'Should catch "Oasis App is not open"' , async ( ) => {
2631 mockAppIsOpen ( 'BOLOS' )
27- const accountsMainMenu = Ledger . enumerateAccounts ( { } as any , 0 )
32+ const accountsMainMenu = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy , 0 )
2833 await expect ( accountsMainMenu ) . rejects . toThrowError ( WalletError )
2934 await expect ( accountsMainMenu ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerOasisAppIsNotOpen )
3035
3136 mockAppIsOpen ( 'Ethereum' )
32- const accountsEth = Ledger . enumerateAccounts ( { } as any , 0 )
37+ const accountsEth = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy , 0 )
3338 await expect ( accountsEth ) . rejects . toThrowError ( WalletError )
3439 await expect ( accountsEth ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerOasisAppIsNotOpen )
3540 } )
3641
37- it ( 'Should enumerate and return the accounts' , async ( ) => {
42+ it ( 'Should enumerate and return adr8 accounts' , async ( ) => {
43+ mockAppIsOpen ( 'Oasis' )
44+ const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
45+ pubKey . mockResolvedValueOnce ( { return_code : 0x9000 , pk : Buffer . from ( new Uint8Array ( [ 1 , 2 , 3 ] ) ) } )
46+ pubKey . mockResolvedValueOnce ( { return_code : 0x9000 , pk : Buffer . from ( new Uint8Array ( [ 4 , 5 , 6 ] ) ) } )
47+
48+ const accounts = await Ledger . enumerateAccounts ( { } as any , DerivationPathTypeAdr8 , 2 )
49+ expect ( accounts ) . toHaveLength ( 2 )
50+ expect ( accounts ) . toContainEqual ( { path : [ 44 , 474 , 0 ] , publicKey : new Uint8Array ( [ 1 , 2 , 3 ] ) } )
51+ expect ( accounts ) . toContainEqual ( { path : [ 44 , 474 , 1 ] , publicKey : new Uint8Array ( [ 4 , 5 , 6 ] ) } )
52+ } )
53+
54+ it ( 'Should enumerate and return legacy accounts' , async ( ) => {
3855 mockAppIsOpen ( 'Oasis' )
3956 const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
4057 pubKey . mockResolvedValueOnce ( { return_code : 0x9000 , pk : Buffer . from ( new Uint8Array ( [ 1 , 2 , 3 ] ) ) } )
4158 pubKey . mockResolvedValueOnce ( { return_code : 0x9000 , pk : Buffer . from ( new Uint8Array ( [ 4 , 5 , 6 ] ) ) } )
4259
43- const accounts = await Ledger . enumerateAccounts ( { } as any , 2 )
60+ const accounts = await Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy , 2 )
4461 expect ( accounts ) . toHaveLength ( 2 )
4562 expect ( accounts ) . toContainEqual ( { path : [ 44 , 474 , 0 , 0 , 0 ] , publicKey : new Uint8Array ( [ 1 , 2 , 3 ] ) } )
4663 expect ( accounts ) . toContainEqual ( { path : [ 44 , 474 , 0 , 0 , 1 ] , publicKey : new Uint8Array ( [ 4 , 5 , 6 ] ) } )
@@ -51,7 +68,7 @@ describe('Ledger Library', () => {
5168 const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
5269 pubKey . mockResolvedValueOnce ( { return_code : 0x6804 } )
5370
54- const accounts = Ledger . enumerateAccounts ( { } as any )
71+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy )
5572 await expect ( accounts ) . rejects . toThrowError ( WalletError )
5673 await expect ( accounts ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerCannotOpenOasisApp )
5774 } )
@@ -61,7 +78,7 @@ describe('Ledger Library', () => {
6178 const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
6279 pubKey . mockResolvedValueOnce ( { return_code : 0x6400 } )
6380
64- const accounts = Ledger . enumerateAccounts ( { } as any )
81+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy )
6582 await expect ( accounts ) . rejects . toThrowError ( WalletError )
6683 await expect ( accounts ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerAppVersionNotSupported )
6784 } )
@@ -71,7 +88,7 @@ describe('Ledger Library', () => {
7188 const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
7289 pubKey . mockResolvedValueOnce ( { return_code : - 1 , error_message : 'unknown dummy error' } )
7390
74- const accounts = Ledger . enumerateAccounts ( { } as any )
91+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy )
7592 await expect ( accounts ) . rejects . toThrowError ( WalletError )
7693 await expect ( accounts ) . rejects . toThrow ( / u n k n o w n d u m m y e r r o r / )
7794 await expect ( accounts ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerUnknownError )
@@ -96,7 +113,7 @@ describe('Ledger Library', () => {
96113 it ( 'Should fail without USB transport' , ( ) => {
97114 const signer = new LedgerSigner ( {
98115 type : WalletType . Ledger ,
99- path : [ 44 , 474 , 0 , 0 , 0 ] ,
116+ path : Ledger . mustGetPath ( DerivationPathTypeAdr8 , 0 ) ,
100117 publicKey : '00' ,
101118 } as Wallet )
102119
@@ -111,7 +128,7 @@ describe('Ledger Library', () => {
111128
112129 const signer = new LedgerSigner ( {
113130 type : WalletType . Ledger ,
114- path : [ 44 , 474 , 0 , 0 , 0 ] ,
131+ path : Ledger . mustGetPath ( DerivationPathTypeAdr8 , 0 ) ,
115132 publicKey : 'aabbcc' ,
116133 } as Wallet )
117134
@@ -124,7 +141,7 @@ describe('Ledger Library', () => {
124141
125142 const signer = new LedgerSigner ( {
126143 type : WalletType . Ledger ,
127- path : [ 44 , 474 , 0 , 0 , 0 ] ,
144+ path : Ledger . mustGetPath ( DerivationPathTypeAdr8 , 0 ) ,
128145 publicKey : '00' ,
129146 } as Wallet )
130147
@@ -140,7 +157,7 @@ describe('Ledger Library', () => {
140157
141158 const signer = new LedgerSigner ( {
142159 type : WalletType . Ledger ,
143- path : [ 44 , 474 , 0 , 0 , 0 ] ,
160+ path : Ledger . mustGetPath ( DerivationPathTypeAdr8 , 0 ) ,
144161 publicKey : '00' ,
145162 } as Wallet )
146163
0 commit comments