-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from Zondax/migrating_to_ts
- Loading branch information
Showing
26 changed files
with
1,000 additions
and
15,790 deletions.
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
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 |
---|---|---|
@@ -1,30 +1,75 @@ | ||
# ledger-substrate (JS Integration) | ||
|
||
[![Main](https://github.com/Zondax/ledger-substrate-js/workflows/Main/badge.svg)](https://github.com/Zondax/ledger-substrate-gen/actions?query=workflow%3AMain) | ||
|
||
[![Main](https://github.com/Zondax/ledger-substrate-js/workflows/Main/badge.svg)](https://github.com/Zondax/ledger-substrate-js/actions?query=workflow%3AMain) | ||
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
[![npm version](https://badge.fury.io/js/%40zondax%2Fledger-substrate.svg)](https://badge.fury.io/js/%40zondax%2Fledger-substrate) | ||
|
||
|
||
This package provides a basic client library to communicate with Substrate Apps running in a Ledger Nano S/X devices | ||
|
||
This package provides a basic client library to communicate with Substrate Apps running in a Ledger Nano S/S+/X devices | ||
Additionally, it provides a hd_key_derivation function to retrieve the keys that Ledger apps generate with | ||
BIP32-ED25519. Warning: the hd_key_derivation function is not audited and depends on external pacakges. We recommend | ||
using the official Substrate Ledger apps in recovery mode. | ||
|
||
# Run Tests | ||
# Available commands | ||
|
||
| Operation | Response | Command | | ||
| ---------- | ---------------- | ----------------------- | | ||
| getVersion | app version | --------------- | | ||
| getAddress | pubkey + address | path + ( showInDevice ) | | ||
| sign | signed message | path + message | | ||
|
||
getAddress command requires that you set the derivation path (account, change, index) and has an option parameter to display the address on the device. By default, it will retrieve the information without confirmation from the user. | ||
|
||
# Add new chain | ||
|
||
If you want to add support for your chain, you just need to create a PR in this repository adding the parameters that belong to the chain. | ||
Go to [supported APPs](./src/supported_apps.ts) and add a new entry at the end of the file. | ||
|
||
``` | ||
{ | ||
name: 'ChainName', | ||
cla: 0xFF, | ||
slip0044: 0x80000162, | ||
ss58_addr_type: 7391, | ||
}, | ||
``` | ||
|
||
Take the last used CLA and pick the following number. This is just an ID for the app that is used in APDU protocol. This is probably the easiest way to get a free CLA. | ||
|
||
- Prepare your Ledger device (for instance, use https://github.com/zondax/ledger-kusama) | ||
For Slip0044 parameter, you might want to [register here](https://github.com/satoshilabs/slips/blob/master/slip-0044.md) as well. | ||
|
||
- Prepare as development device: | ||
SS58 prefix have no limitation whatsoever, you just have to set an uint16 number that is used in your chain. | ||
|
||
- Build & load the Kusama app | ||
# Testing with real devices | ||
|
||
- Load the Kusama App | ||
It is possible to test this package with a real Ledger Nano device. To accomplish that, you will need to follow these steps: | ||
|
||
- Install all dependencies and run tests | ||
- Install the application in the Ledger device | ||
- Install the dependencies from this project | ||
- Run tests | ||
|
||
```shell script | ||
yarn install | ||
yarn test:integration | ||
yarn test | ||
``` | ||
|
||
## Example: | ||
|
||
Go and take the [latest release](https://github.com/Zondax/ledger-kusama/releases/tag/v12.9270.0) from repository (in this case Kusama). | ||
|
||
Download the installer script for your device but bear in mind that NanoX does not allow side loading applications. Give execution permission and run the script. | ||
|
||
```shell script | ||
chmod +x installer_nano_device.sh | ||
./installer_nano_device.sh load | ||
``` | ||
|
||
Modify these values from [testing script](./tests/integration.test.ts) before running the tests: | ||
|
||
```shell script | ||
const CHAIN = 'Kusama' | ||
const YOUR_PUBKEY = 'd280b24dface41f31006e5a2783971fc5a66c862dd7d08f97603d2902b75e47a' | ||
const YOUR_ADDRESS = 'HLKocKgeGjpXkGJU6VACtTYJK4ApTCfcGRw51E5jWntcsXv' | ||
const YOUR_BLOB = '0400ffbc10f71d63e0da1b9e7ee2eb4037466551dc32b9d4641aafd73a65970fae4202286beed502000022040000b0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe280b332587f46c556aa806781884284f50d90b8c1b02488a059700673c93f41c' | ||
``` | ||
|
||
Run tests and you will see how this module communicates with your device. |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,28 +1,7 @@ | ||
// For a detailed explanation regarding each configuration property, visit: | ||
// https://jestjs.io/docs/en/configuration.html | ||
|
||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
transformIgnorePatterns: ['^.+\\.js$'], | ||
modulePaths: ['<rootDir>/src', '<rootDir>/tests'], | ||
|
||
moduleNameMapper: { | ||
'^jest$': '<rootDir>/tests/jest.js', | ||
'^index.js$': '<rootDir>/src/index.js', | ||
}, | ||
|
||
// Automatically clear mock calls and instances between every test | ||
clearMocks: true, | ||
|
||
// The directory where Jest should output its coverage files | ||
coverageDirectory: 'coverage', | ||
|
||
// A list of paths to directories that Jest should use to search for files in | ||
roots: ['<rootDir>'], | ||
|
||
runner: 'jest-serial-runner', | ||
|
||
// The test environment that will be used for testing | ||
testEnvironment: 'node', | ||
|
||
// The glob patterns Jest uses to detect test files | ||
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)', '**/?(*.)+(ispec|test).[tj]s?(x)'], | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,91 +1,105 @@ | ||
{ | ||
"name": "@zondax/ledger-substrate", | ||
"version": "0.17.9", | ||
"description": "JS / Node API for Kusama/Polkadot app running (Ledger Nano S/X)", | ||
"author": "Zondax GmbH", | ||
"author": "Zondax AG", | ||
"license": "Apache-2.0", | ||
"version": "0.17.9", | ||
"description": "TS / Node API for Substrate based apps running on Ledger Nano S/S+/X", | ||
"main": "./dist/index.js", | ||
"typings": "./dist/index.d.ts", | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"build": "babel src --out-dir dist", | ||
"build:ci": "yarn build && cp -f src/index.d.ts dist", | ||
"test:unit": "jest -c jest.config.unit.js", | ||
"test:integration": "jest -c jest.config.integration.js --runInBand --detectOpenHandles", | ||
"linter": "eslint --ext .ts,.tsx,.js,.jsx --ignore-path .eslintignore .", | ||
"linter:fix": "yarn linter --fix", | ||
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/zondax/ledger-substrate-js.git" | ||
}, | ||
"keywords": [ | ||
"Ledger", | ||
"Javascript", | ||
"Typescript", | ||
"Substrate", | ||
"Kusama", | ||
"Polkadot" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/Zondax/ledger-substrate-js/issues" | ||
}, | ||
"homepage": "https://github.com/Zondax/ledger-substrate-js", | ||
"resolutions": { | ||
"@ledgerhq/hw-transport-node-hid/@ledgerhq/hw-transport-node-hid-noevents": "6.27.1" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.14.8", | ||
"@ledgerhq/hw-transport": "^6.2.0", | ||
"bip32": "2.0.6", | ||
"@babel/runtime": "^7.18.9", | ||
"@ledgerhq/hw-transport": "6.27.1", | ||
"bip32": "3.0.1", | ||
"bip32-ed25519": "https://github.com/Zondax/bip32-ed25519", | ||
"bip39": "3.0.4", | ||
"blakejs": "^1.1.1", | ||
"bs58": "^4.0.1", | ||
"blakejs": "^1.2.1", | ||
"bs58": "^5.0.0", | ||
"chalk": "4", | ||
"hash.js": "^1.1.7" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.14.8", | ||
"@babel/core": "^7.14.8", | ||
"@babel/node": "^7.14.7", | ||
"@babel/plugin-transform-runtime": "^7.14.5", | ||
"@babel/preset-env": "^7.14.8", | ||
"@ledgerhq/hw-transport-node-hid": "^6.2.0", | ||
"@ledgerhq/hw-transport-webusb": "^6.2.0", | ||
"@ledgerhq/logs": "^6.2.0", | ||
"@types/fs-extra": "^9.0.12", | ||
"@types/jest": "^26.0.24", | ||
"@babel/cli": "^7.18.10", | ||
"@babel/core": "^7.18.10", | ||
"@babel/node": "^7.18.10", | ||
"@babel/plugin-transform-runtime": "^7.18.9", | ||
"@babel/preset-env": "^7.18.9", | ||
"@ledgerhq/hw-transport-node-hid": "6.27.1", | ||
"@ledgerhq/hw-transport-webusb": "6.27.1", | ||
"@ledgerhq/logs": "^6.10.0", | ||
"@swc/core": "^1.2.237", | ||
"@types/figlet": "^1.5.4", | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/jest": "26", | ||
"@types/ledgerhq__hw-transport": "^4.21.4", | ||
"@types/minimist": "^1.2.2", | ||
"@types/node": "^18.7.6", | ||
"@types/pngjs": "^6.0.1", | ||
"@types/sleep": "^0.0.8", | ||
"@typescript-eslint/eslint-plugin": "^4.28.4", | ||
"@typescript-eslint/parser": "^4.28.4", | ||
"@typescript-eslint/eslint-plugin": "^5.33.1", | ||
"@typescript-eslint/parser": "^5.33.1", | ||
"babel-eslint": "^10.1.0", | ||
"babel-jest": "^27.0.6", | ||
"core-js": "^3.15.2", | ||
"babel-jest": "26", | ||
"copyfiles": "^2.4.1", | ||
"core-js": "^3.24.1", | ||
"crypto-js": "4.1.1", | ||
"ed25519-supercop": "^2.0.1", | ||
"eslint": "^7.31.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.23.4", | ||
"eslint-plugin-jest": "^24.4.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"eslint": "^8.22.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jest": "^26.8.3", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"figlet": "^1.5.2", | ||
"jest": "^26", | ||
"jest-serial-runner": "^1.1.0", | ||
"jest-runner": "^26", | ||
"jest-serial-runner": "^1.2.0", | ||
"js-sha512": "^0.8.0", | ||
"prettier": "^2.3.2", | ||
"ts-jest": "^26", | ||
"typescript": "^4.3.5" | ||
"minimist": "^1.2.6", | ||
"prettier": "^2.7.1", | ||
"ts-jest": "26", | ||
"ts-node": "^10.8.1", | ||
"typescript": "^4.7.4" | ||
}, | ||
"moduleDirectories": [ | ||
"node_modules", | ||
"dist" | ||
], | ||
"postcss": { | ||
"plugins": { | ||
"autoprefixer": {} | ||
} | ||
}, | ||
"browserslist": [ | ||
"> 1%", | ||
"last 2 versions" | ||
"files": [ | ||
"dist/**", | ||
"LICENSE", | ||
"package.json" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"build": "tsc && yarn copy-files", | ||
"copy-files": "copyfiles -u 0 src/**/*.proto dist/", | ||
"test:integration": "yarn build && jest -t 'Integration'", | ||
"test:key-derivation": "yarn build && jest -t 'KeyDerivation'", | ||
"supported": "ts-node src/index.ts supported", | ||
"build:ci": "yarn build && cp -f src/index.d.ts dist", | ||
"test:unit": "jest -c jest.config.unit.js", | ||
"linter": "eslint --ext .ts,.tsx,.js,.jsx --ignore-path .eslintignore . --max-warnings 0", | ||
"linter:fix": "yarn linter --fix", | ||
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"" | ||
} | ||
} |
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,25 @@ | ||
/** ****************************************************************************** | ||
* (c) 2019 - 2022 ZondaX AG | ||
* (c) 2016-2017 Ledger | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
******************************************************************************* */ | ||
import chalk from 'chalk' | ||
import { supportedApps } from '../supported_apps' | ||
|
||
export function printSupported() { | ||
console.log(chalk.blueBright('Supported chains:')) | ||
for (const chain of supportedApps) { | ||
console.log(chalk.white(chain.name)) | ||
} | ||
} |
Oops, something went wrong.