-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e6158b
commit e6b1462
Showing
7 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import TransportBLE from '@ledgerhq/react-native-hw-transport-ble'; | ||
|
||
export const getAppAndVersion = async ( | ||
transport: TransportBLE, | ||
): Promise<{ | ||
name: string; | ||
version: string; | ||
flags: number | Buffer; | ||
}> => { | ||
const r = await transport.send(0xb0, 0x01, 0x00, 0x00); | ||
|
||
let i = 0; | ||
const format = r[i++]; | ||
|
||
if (format !== 1) { | ||
throw new Error('getAppAndVersion: format not supported'); | ||
} | ||
|
||
const nameLength = r[i++]; | ||
const name = r.slice(i, (i += nameLength)).toString('ascii'); | ||
const versionLength = r[i++]; | ||
const version = r.slice(i, (i += versionLength)).toString('ascii'); | ||
const flagLength = r[i++]; | ||
const flags = r.slice(i, (i += flagLength)); | ||
return { | ||
name, | ||
version, | ||
flags, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import TransportBLE from '@ledgerhq/react-native-hw-transport-ble'; | ||
|
||
export const openApp = async ( | ||
transport: TransportBLE, | ||
name: string, | ||
): Promise<void> => { | ||
await transport.send(0xe0, 0xd8, 0x00, 0x00, Buffer.from(name, 'ascii')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import TransportBLE from '@ledgerhq/react-native-hw-transport-ble'; | ||
|
||
export const quitApp = async (transport: TransportBLE) => { | ||
await transport.send(0xb0, 0xa7, 0x00, 0x00); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import TransportBLE from '@ledgerhq/react-native-hw-transport-ble'; | ||
import {getAppAndVersion} from './get-app-and-version'; | ||
import {openApp} from './open-app'; | ||
import {quitApp} from './quit-app'; | ||
|
||
const dashboardNames = ['BOLOS', 'OLOS\u0000']; | ||
export const isDashboardName = (name: string) => dashboardNames.includes(name); | ||
|
||
export const suggestApp = async ( | ||
transport: TransportBLE, | ||
name: string, | ||
): Promise<void> => { | ||
try { | ||
const v = await getAppAndVersion(transport); | ||
|
||
if (v.name !== name) { | ||
if (!isDashboardName(v.name)) { | ||
await quitApp(transport); | ||
} | ||
|
||
await openApp(transport, name); | ||
} | ||
} catch (e) { | ||
console.log('suggestApp', e); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters