Skip to content

OneKey Communication Daemon (written in Go)

License

Notifications You must be signed in to change notification settings

OneKeyHQ/onekey-bridge

 
 

Repository files navigation

OneKey Bridge

You could obtain binary files and installer packages at release page

How To Build (Both binary and installer)

Please refer to Build.md

All version numbers are controlled by VERSION at root level, no need to change other files

For things work properly , be sure to follow build methods documented in Build.md

Emulator support

OneKey bridge has emulator support, but it's disabled by default.

To enable emulator support, launch with -e parameter followed by port, for example ./onekeyd -e 21324

To disable all USB in order to run on some virtual environments,launch with -u=false parameter, for example ./onekeyd -u=false

If you want change default launch options, you may have to change service accordingly

Edit Default Service Launch Options

On Linux, sudo systemctl edit --full onekeyd.service to edit the service control file

On MacOS, open /Library/LaunchAgents/so.onekey.bridge.onekeyd.plist to edit the service control file

On Windows, open shell:startup folder, then edit the OneKey Bridge.lnk file

API documentation

onekey-bridge starts a HTTP server on http://localhost:21320. AJAX calls are only enabled from onekey.so subdomains.

Server supports following API calls:

url
method
parameters result type description
/
POST
{version: string} Returns current version of bridge
/enumerate
POST
Array<{path: string,
session: string | null}>
Lists devices.
path uniquely defines device between more connected devices. Two different devices (or device connected and disconnected) will return different paths.
If session is null, nobody else is using the device; if it's string, it identifies who is using it.
/listen
POST
request body: previous, as JSON like enumerate Listen to changes and returns either on change or after 30 second timeout. Compares change from previous that is sent as a parameter. "Change" is both connecting/disconnecting and session change.
/acquire/PATH/PREVIOUS
POST
PATH: path of device
PREVIOUS: previous session (or string "null")
{session: string} Acquires the device at PATH. By "acquiring" the device, you are claiming the device for yourself.
Before acquiring, checks that the current session is PREVIOUS.
If two applications call acquire on a newly connected device at the same time, only one of them succeed.
/release/SESSION
POST
SESSION: session to release {} Releases the device with the given session.
By "releasing" the device, you claim that you don't want to use the device anymore.
/call/SESSION
POST
SESSION: session to call

request body: hexadecimal string
hexadecimal string Both input and output are hexadecimal, encoded in following way:
first 2 bytes (4 characters in the hexadecimal) is the message type
next 4 bytes (8 in hex) is length of the data
the rest is the actual encoded protobuf data.
Protobuf messages are defined in this protobuf file and the app, calling onekey, should encode/decode it itself.
/post/SESSION
POST
SESSION: session to call

request body: hexadecimal string
0 Similar to call, just doesn't read response back. Usable mainly for debug link.
/read/SESSION
POST
SESSION: session to call 0 Similar to call, just doesn't post, only reads. Usable mainly for debug link.

Debug link support

OneKey Bridge has support for debug link.

To support an emulator with debug link, run

./onekeyd -ed 21324:21320 -u=false

this will detect emulator debug link on port 21320, with regular device on 21324.

To support WebUSB devices with debug link, no option is needed, just run onekey-bridge.

In the enumerate and listen results, there are now two new fields: debug and debugSession. debug signals that device can receive debug link messages.

Session management is separate for debug link and normal interface, so you can have two applications - one controlling OneKey and one "normal".

There are new calls:

  • /debug/acquire/PATH, which has the same path as normal acquire, and returns a SESSION
  • /debug/release/SESSION releases session
  • /debug/call/SESSION, /debug/post/SESSION, /debug/read/SESSION work as with normal interface

The session IDs for debug link start with the string "debug".

Copyright

About

OneKey Communication Daemon (written in Go)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 83.7%
  • Go 15.0%
  • Shell 1.3%