1- import { DerivationPathLegacy , DerivationPathAdr8 , 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,34 +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 , DerivationPathLegacy , 0 )
21+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy , 0 )
2222 await expect ( accounts ) . resolves . toEqual ( [ ] )
2323 } )
2424 it ( 'enumerateAccounts should pass when Oasis App is open' , async ( ) => {
2525 mockAppIsOpen ( 'Oasis' )
26- const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathAdr8 , 0 )
26+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeAdr8 , 0 )
2727 await expect ( accounts ) . resolves . toEqual ( [ ] )
2828 } )
2929
3030 it ( 'Should catch "Oasis App is not open"' , async ( ) => {
3131 mockAppIsOpen ( 'BOLOS' )
32- const accountsMainMenu = Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy , 0 )
32+ const accountsMainMenu = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy , 0 )
3333 await expect ( accountsMainMenu ) . rejects . toThrowError ( WalletError )
3434 await expect ( accountsMainMenu ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerOasisAppIsNotOpen )
3535
3636 mockAppIsOpen ( 'Ethereum' )
37- const accountsEth = Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy , 0 )
37+ const accountsEth = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy , 0 )
3838 await expect ( accountsEth ) . rejects . toThrowError ( WalletError )
3939 await expect ( accountsEth ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerOasisAppIsNotOpen )
4040 } )
4141
42- it ( 'Should enumerate and return the accounts' , async ( ) => {
42+ it ( 'Should enumerate and return adr8 accounts' , async ( ) => {
4343 mockAppIsOpen ( 'Oasis' )
4444 const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
4545 pubKey . mockResolvedValueOnce ( { return_code : 0x9000 , pk : Buffer . from ( new Uint8Array ( [ 1 , 2 , 3 ] ) ) } )
4646 pubKey . mockResolvedValueOnce ( { return_code : 0x9000 , pk : Buffer . from ( new Uint8Array ( [ 4 , 5 , 6 ] ) ) } )
4747
48- const accounts = await Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy , 2 )
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 ( ) => {
55+ mockAppIsOpen ( 'Oasis' )
56+ const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
57+ pubKey . mockResolvedValueOnce ( { return_code : 0x9000 , pk : Buffer . from ( new Uint8Array ( [ 1 , 2 , 3 ] ) ) } )
58+ pubKey . mockResolvedValueOnce ( { return_code : 0x9000 , pk : Buffer . from ( new Uint8Array ( [ 4 , 5 , 6 ] ) ) } )
59+
60+ const accounts = await Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy , 2 )
4961 expect ( accounts ) . toHaveLength ( 2 )
5062 expect ( accounts ) . toContainEqual ( { path : [ 44 , 474 , 0 , 0 , 0 ] , publicKey : new Uint8Array ( [ 1 , 2 , 3 ] ) } )
5163 expect ( accounts ) . toContainEqual ( { path : [ 44 , 474 , 0 , 0 , 1 ] , publicKey : new Uint8Array ( [ 4 , 5 , 6 ] ) } )
@@ -56,7 +68,7 @@ describe('Ledger Library', () => {
5668 const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
5769 pubKey . mockResolvedValueOnce ( { return_code : 0x6804 } )
5870
59- const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy )
71+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy )
6072 await expect ( accounts ) . rejects . toThrowError ( WalletError )
6173 await expect ( accounts ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerCannotOpenOasisApp )
6274 } )
@@ -66,7 +78,7 @@ describe('Ledger Library', () => {
6678 const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
6779 pubKey . mockResolvedValueOnce ( { return_code : 0x6400 } )
6880
69- const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy )
81+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy )
7082 await expect ( accounts ) . rejects . toThrowError ( WalletError )
7183 await expect ( accounts ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerAppVersionNotSupported )
7284 } )
@@ -76,7 +88,7 @@ describe('Ledger Library', () => {
7688 const pubKey : jest . Mock < any > = OasisApp . prototype . publicKey
7789 pubKey . mockResolvedValueOnce ( { return_code : - 1 , error_message : 'unknown dummy error' } )
7890
79- const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathLegacy )
91+ const accounts = Ledger . enumerateAccounts ( { } as any , DerivationPathTypeLegacy )
8092 await expect ( accounts ) . rejects . toThrowError ( WalletError )
8193 await expect ( accounts ) . rejects . toThrow ( / u n k n o w n d u m m y e r r o r / )
8294 await expect ( accounts ) . rejects . toHaveProperty ( 'type' , WalletErrors . LedgerUnknownError )
@@ -116,7 +128,7 @@ describe('Ledger Library', () => {
116128
117129 const signer = new LedgerSigner ( {
118130 type : WalletType . Ledger ,
119- path : Ledger . mustGetPath ( DerivationPathLegacy , 0 ) ,
131+ path : Ledger . mustGetPath ( DerivationPathTypeAdr8 , 0 ) ,
120132 publicKey : 'aabbcc' ,
121133 } as Wallet )
122134
0 commit comments