├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── electron.js
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
├── preload.js
└── robots.txt
├── src
├── App.css
├── App.tsx
├── index.css
├── index.tsx
├── logo.svg
└── react-app-env.d.ts
├── tsconfig.json
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Test Applicaion for Firma-JS-Ledger (React-Web and Electron Desktop App)
2 |
3 | ## Install
4 |
5 | In the project directory, you can run:
6 | ```
7 | yarn
8 | ```
9 |
10 | ## Run React Web
11 | ```
12 | npm run react:start
13 | ```
14 | - Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
15 |
16 |
17 |
18 |
19 |
20 | ## Run Electron Desktop App (Windows/MacOs/Linux support)
21 | ```
22 | npm run react:start
23 |
24 | // open another terminal and run
25 | npm run electron:start
26 | ```
27 |
28 | - The application will be launched automatically in the development mode
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ledger-test",
3 | "version": "0.1.0",
4 | "private": true,
5 | "homepage": "./",
6 | "main": "./public/electron.js",
7 | "build": {
8 | "appId": "com.firmachain.wallet",
9 | "files": [
10 | "public/**/*",
11 | "build/**/*",
12 | "node_modules/**/*"
13 | ],
14 | "directories": {
15 | "buildResources": "assets"
16 | }
17 | },
18 | "dependencies": {
19 | "@firmachain/firma-js": "0.2.45",
20 | "@firmachain/firma-js-ledger": "0.0.8",
21 | "@ledgerhq/hw-transport-node-hid": "^6.20.0",
22 | "@ledgerhq/hw-transport-node-hid-singleton": "^6.11.2",
23 | "@ledgerhq/hw-transport-webhid": "^6.20.0",
24 | "@testing-library/jest-dom": "^5.11.4",
25 | "@testing-library/react": "^11.1.0",
26 | "@testing-library/user-event": "^12.1.10",
27 | "@types/jest": "^26.0.15",
28 | "@types/node": "^12.0.0",
29 | "@types/react": "^17.0.0",
30 | "@types/react-dom": "^17.0.0",
31 | "react": "^17.0.2",
32 | "react-dom": "^17.0.2",
33 | "react-scripts": "4.0.3",
34 | "typescript": "^4.1.2",
35 | "web-vitals": "^1.0.1"
36 | },
37 | "devDependencies": {
38 | "concurrently": "^6.2.1",
39 | "cross-env": "^7.0.3",
40 | "electron": "^14.0.1",
41 | "electron-builder": "^22.11.7",
42 | "wait-on": "^6.0.0"
43 | },
44 | "scripts": {
45 | "start": "concurrently \"npm run react:start\" \"npm run electron:start\"",
46 | "react:start": "react-scripts start",
47 | "react:build": "react-scripts build",
48 | "electron:start": "wait-on http://localhost:3000 && electron ."
49 | },
50 | "eslintConfig": {
51 | "extends": [
52 | "react-app",
53 | "react-app/jest"
54 | ]
55 | },
56 | "browserslist": {
57 | "production": [
58 | ">0.2%",
59 | "not dead",
60 | "not op_mini all"
61 | ],
62 | "development": [
63 | "last 1 chrome version",
64 | "last 1 firefox version",
65 | "last 1 safari version"
66 | ]
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/public/electron.js:
--------------------------------------------------------------------------------
1 |
2 | const { app, BrowserWindow, shell, ipcMain } = require("electron");
3 | const electron = require("electron");
4 | const path = require("path");
5 |
6 | const TransportHID = require('@ledgerhq/hw-transport-node-hid').default
7 |
8 | const { FirmaWebLedgerWallet } = require("@firmachain/firma-js-ledger");
9 |
10 | electron.app.setPath("userData", path.join(electron.app.getPath("home"), ".firma-station"));
11 |
12 | let ledgerWallet = new FirmaWebLedgerWallet(TransportHID);
13 |
14 | function initialize() {
15 | function createWindow() {
16 | const size = electron.screen.getPrimaryDisplay().workAreaSize;
17 | const originWidth = size.width;
18 | const width = originWidth > 1080 ? parseInt(1080 + (originWidth - 1080) * 0.5) : originWidth;
19 | const height = parseInt(width / (1920 / 1080));
20 |
21 | const windowOptions = {
22 | minWidth: width,
23 | minHeight: height,
24 | width: width,
25 | height: height,
26 | title: app.getName(),
27 | titleBarStyle: "hiddenInset",
28 | webPreferences: {
29 | nodeIntegration: false,
30 | enableRemoteModule: false,
31 | nativeWindowOpen: true,
32 | webSecurity: false,
33 | preload: path.resolve(__dirname, "preload.js"),
34 | },
35 | resizable: true,
36 | };
37 | mainWindow = new BrowserWindow(windowOptions);
38 | mainWindow.setMenu(null);
39 | mainWindow.loadURL(
40 | "http://localhost:3000"
41 | // url.format({
42 | // pathname: path.join(__dirname, "/../build/index.html"),
43 | // protocol: "file",
44 | // slashes: true,
45 | // })
46 | );
47 |
48 | mainWindow.webContents.openDevTools();
49 |
50 | mainWindow.once("ready-to-show", () => {
51 | mainWindow.show();
52 | });
53 |
54 | mainWindow.on("closed", () => {
55 | mainWindow = null;
56 | });
57 | mainWindow.on("will-resize", (event) => {
58 | event.preventDefault();
59 | });
60 | }
61 |
62 | app.on("ready", createWindow);
63 |
64 | app.on("window-all-closed", function () {
65 | app.quit();
66 | });
67 |
68 | app.on("web-contents-created", (e, webContents) => {
69 | webContents.on("new-window", (event, url) => {
70 | event.preventDefault();
71 |
72 | if (url.match(/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/g)) {
73 | shell.openExternal(url);
74 | }
75 | });
76 | });
77 |
78 | ipcMain.on("ledger-showAddressOnDevice", async (event, arg) => {
79 |
80 | await ledgerWallet.showAddressOnDevice();
81 | event.returnValue = "";
82 | });
83 |
84 | ipcMain.on("ledger-getAddress", async (event, arg) => {
85 |
86 | let address = await ledgerWallet.getAddress();
87 | event.returnValue = address;
88 | });
89 |
90 | ipcMain.on("ledger-getAddressAndPublicKey", async (event, arg) => {
91 |
92 | let data = await ledgerWallet.getAddressAndPublicKey();
93 | event.returnValue = data;
94 | });
95 |
96 | ipcMain.on("ledger-sign", async (event, arg) => {
97 |
98 | let message = await ledgerWallet.sign(arg["message"]);
99 | event.returnValue = message;
100 | });
101 |
102 | ipcMain.on("ledger-getPublicKey", async (event, arg) => {
103 |
104 | let message = await ledgerWallet.getPublicKey();
105 | event.returnValue = message;
106 | });
107 |
108 | }
109 |
110 | initialize();
111 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FirmaChain/ledger-test-app/afc1be916eea0e6432bd9f60efe0accd69391437/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |