Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trezor: Use connect v9. #3911

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*~
app/dist/
app/dist-trezor/
app/trezor-prebuild/build/
app/main.js
app/main.js.map
app/i18n/lib/
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*~
app/dist/
app/dist-trezor/
app/main.js
app/main.js.map
app/main.js.LICENSE.txt
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/bin
/node_modules
/app/dist
/app/dist-trezor
/app/trezor-prebuild/build
/app/middleware/ln/*_pb.js
/app/middleware/ln/google/api/*_pb.js
/app/middleware/walletrpc/*_pb.js
Expand Down
34 changes: 21 additions & 13 deletions app/actions/TrezorActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ import {
SIGNMESSAGE_SUCCESS
} from "./ControlActions";
import { getAmountFromTxInputs, getTxFromInputs } from "./TransactionActions";

const session = require("trezor-connect").default;
const {
import {
TRANSPORT_EVENT,
UI,
UI_EVENT,
DEVICE_EVENT
} = require("trezor-connect");
} from "@trezor/connect-web";
const session = require("@trezor/connect-web").default;
const CHANGE = "device-changed";
const DISCONNECT = "device-disconnect";
const CONNECT = "device-connect";
Expand All @@ -40,32 +39,24 @@ const TRANSPORT_ERROR = "transport-error";
const TRANSPORT_START = "transport-start";
const BOOTLOADER_MODE = "bootloader";

let setListeners = false;

export const TRZ_WALLET_CLOSED = "TRZ_WALLET_CLOSED";
export const TRZ_TREZOR_ENABLED = "TRZ_TREZOR_ENABLED";

// enableTrezor attepts to start a connection with connect if none exist and
// connect to a trezor device.
export const enableTrezor = () => (dispatch, getState) => {
dispatch({ type: TRZ_TREZOR_ENABLED });

if (!setListeners) {
setDeviceListeners(dispatch, getState);
setListeners = true;
}
connect()(dispatch, getState);
};

export const initTransport = async (session, debug) => {
await session
.init({
connectSrc: "./",
env: "web",
transports: ["BridgeTransport"],
lazyLoad: false,
popup: false,
transportReconnect: false,
webusb: false,
manifest: {
email: "joegruffins@gmail.com",
appUrl: "https://github.com/decred/decrediton"
Expand All @@ -82,6 +73,8 @@ export const TRZ_CONNECT_FAILED = "TRZ_CONNECT_FAILED";
export const TRZ_CONNECT_SUCCESS = "TRZ_CONNECT_SUCCESS";

export const connect = () => async (dispatch, getState) => {
// connected refers to the transport being up and is connected to
// TRZ_DEVICETRANSPORT_START and TRZ_DEVICETRANSPORT_LOST.
const {
trezor: { connected, connectAttempt }
} = getState();
Expand All @@ -90,6 +83,9 @@ export const connect = () => async (dispatch, getState) => {

wallet.allowExternalRequest(EXTERNALREQUEST_TREZOR_BRIDGE);

// If there was a previous connection, dispose will reset it.
await session.dispose();
setDeviceListeners(dispatch, getState);
const debug = getState().trezor.debug;
await initTransport(session, debug).catch((error) => {
dispatch({ error, type: TRZ_CONNECT_FAILED });
Expand Down Expand Up @@ -288,6 +284,18 @@ function setDeviceListeners(dispatch, getState) {

case UI.FIRMWARE_PROGRESS: {
console.log("Trezor update progress: " + event.payload.progress + "%");
break;
}

case UI.SELECT_DEVICE: {
if (event.payload.devices.length > 0) {
session.uiResponse({
type: UI.RECEIVE_DEVICE,
payload: event.payload.devices[0]
});
} else {
// no devices connected, waiting for connection
}
}
}
});
Expand Down
24 changes: 0 additions & 24 deletions app/trezor-iframe.development.html

This file was deleted.

7 changes: 7 additions & 0 deletions app/trezor-prebuild/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This is used to contact trezor-bridge on a separate iframe in the wallet.

It is created by following the instructions at https://github.com/trezor/trezor-suite and is the package in packages/connect-iframe. All binaries have been removed with `$ find ./ -type f -iname "*.bin" -exec rm {} \;`.

Current build is at commit 109db0a3f6fc6fc5cdb24098ee50480692c92dbf

TODO: Build this with webpack.
41 changes: 41 additions & 0 deletions app/trezor-prebuild/build/data/bridge/releases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[
{
"version": [2, 0, 27],
"directory": "bridge/{version}/",
"packages": [
{
"platform": ["deb64"],
"name": "Linux 64-bit (deb)",
"url": "trezor-bridge_{version}_amd64.deb"
},
{
"platform": ["rpm64"],
"name": "Linux 64-bit (rpm)",
"url": "trezor-bridge-{version}-1.x86_64.rpm"
},
{
"platform": ["deb32"],
"name": "Linux 32-bit (deb)",
"url": "trezor-bridge_{version}_i386.deb"
},
{
"platform": ["rpm32"],
"name": "Linux 32-bit (rpm)",
"url": "trezor-bridge-{version}-1.i386.rpm"
},
{
"platform": ["mac"],
"name": "macOS",
"url": "trezor-bridge-{version}.pkg",
"signature": "trezor-bridge-{version}.pkg.asc"
},
{
"platform": ["win32", "win64"],
"name": "Windows",
"url": "trezor-bridge-{version}-win32-install.exe",
"signature": "trezor-bridge-{version}-win32-install.exe.asc"
}
],
"changelog": "* Fix Certificate issue on Windows"
}
]
75 changes: 75 additions & 0 deletions app/trezor-prebuild/build/data/coins-eth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[
{
"blockchain_link": {
"type": "blockbook",
"url": ["https://eth1.trezor.io", "https://eth2.trezor.io"]
},
"chain": "eth",
"chain_id": 1,
"name": "Ethereum",
"shortcut": "ETH",
"slip44": 60,
"support": {
"connect": true,
"suite": true,
"trezor1": "1.6.2",
"trezor2": "2.0.7"
},
"url": "https://ethereum.org"
},
{
"blockchain_link": {
"type": "blockbook",
"url": ["https://sepolia1.trezor.io"]
},
"chain": "sep",
"chain_id": 11155111,
"name": "Sepolia",
"rskip60": false,
"shortcut": "tSEP",
"slip44": 1,
"support": {
"connect": true,
"suite": false,
"trezor1": "1.11.2",
"trezor2": "2.5.2"
},
"url": "https://sepolia.otterscan.io"
},
{
"blockchain_link": {
"type": "blockbook",
"url": ["https://goerli1.trezor.io", "https://goerli2.trezor.io"]
},
"chain": "gor",
"chain_id": 5,
"name": "G\u00f6rli",
"shortcut": "tGOR",
"slip44": 1,
"support": {
"connect": true,
"suite": false,
"trezor1": "1.11.2",
"trezor2": "2.5.2"
},
"url": "https://goerli.net/#about"
},
{
"blockchain_link": {
"type": "blockbook",
"url": ["https://etc1.trezor.io", "https://etc2.trezor.io"]
},
"chain": "etc",
"chain_id": 61,
"name": "Ethereum Classic",
"shortcut": "ETC",
"slip44": 61,
"support": {
"connect": true,
"suite": true,
"trezor1": "1.6.2",
"trezor2": "2.0.7"
},
"url": "https://ethereumclassic.org"
}
]