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

TypeScript migration #174

Merged
merged 28 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f7e409a
chore: add tsconfig and typedoc
mikesposito Mar 2, 2023
fc44970
feat: add typed LedgerBridgeKeyring
mikesposito Mar 2, 2023
ec59fba
test: typed tests for ledger keyring
mikesposito Mar 2, 2023
20fbce7
ci: add build step to circleci
mikesposito Mar 2, 2023
4096579
ci: fix build step
mikesposito Mar 2, 2023
1bb99e4
chore: update linting pipeline
mikesposito Mar 2, 2023
af9e75e
fix: edit package.json main types and files values
mikesposito Mar 2, 2023
3f9bb17
refactor: use @ledgerhq/hw-app-eth to get types
mikesposito Mar 7, 2023
620e852
fix: review refactor
mikesposito Mar 7, 2023
a97989a
refactor: use sharp notation on private methods
mikesposito Mar 7, 2023
2638dea
refactor: use sharp notation on _sendMessage
mikesposito Mar 8, 2023
55d3827
refactor: use sharp notation for _eventListener
mikesposito Mar 8, 2023
b7b797a
refactor: change destroy tests
mikesposito Mar 8, 2023
2aef86d
refator: remove unused private functions
mikesposito Mar 8, 2023
a9eaf21
refactor: apply review suggestions
mikesposito Mar 8, 2023
6215be4
refactor: @mcmire review
mikesposito Mar 13, 2023
ed6b2d3
chore: add comments
mikesposito Mar 13, 2023
510f71c
refactor: update eslint packages
mikesposito Mar 14, 2023
a51f8bc
fix: Event not defined in ci
mikesposito Mar 14, 2023
ba88a6a
fix: eslint version mismatch and fix lint
mikesposito Mar 14, 2023
16f0c7a
refactor: networkApiUrls as enum
mikesposito Mar 20, 2023
3c0c618
fix: use prettierrc from module template
mikesposito Mar 20, 2023
d763535
refactor: isOldStyleEthereumjsTx check
mikesposito Mar 21, 2023
fe77538
refactor: apply @andrewpeters9 suggestion
mikesposito Mar 21, 2023
be80262
refactor: @Gudahtt suggestions
mikesposito Mar 24, 2023
1ae7517
refactor: remove useless promise catch
mikesposito Mar 24, 2023
ab864b0
refactor: use eslint-config-browser
mikesposito Mar 28, 2023
3907c4f
fix: use eslint-config-nodejs on tests
mikesposito Mar 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ workflows:
build-test:
jobs:
- prep-deps
- build:
requires:
- prep-deps
- test-lint:
requires:
- prep-deps
- build
- test-unit:
requires:
- prep-deps
- build
- all-tests-pass:
requires:
- test-lint
Expand All @@ -28,8 +33,24 @@ jobs:
- persist_to_workspace:
root: .
paths:
- node_modules
- build-artifacts
- node_modules
- build-artifacts

build:
docker:
- image: circleci/node:14
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Build
command: |
./scripts/prepack.sh
- persist_to_workspace:
root: .
paths:
- dist

test-lint:
docker:
Expand Down
11 changes: 11 additions & 0 deletions .depcheckrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ignores": [
"@lavamoat/allow-scripts",
"@metamask/auto-changelog",
"@types/*",
"prettier-plugin-packagejson",
"rimraf",
"ts-node",
"typedoc"
]
}
43 changes: 23 additions & 20 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
module.exports = {
root: true,

extends: [
'@metamask/eslint-config',
'@metamask/eslint-config/config/mocha',
'@metamask/eslint-config/config/nodejs',
],

parser: 'babel-eslint',

parserOptions: {
ecmaVersion: 2017,
},

plugins: ['json', 'import'],

globals: {
document: 'readonly',
window: 'readonly',
},
extends: ['@metamask/eslint-config'],

overrides: [
{
files: ['.eslintrc.js'],
files: ['*.ts'],
extends: [
'@metamask/eslint-config-typescript',
'@metamask/eslint-config-browser',
],
},

{
files: ['*.js'],
parserOptions: {
sourceType: 'script',
},
extends: ['@metamask/eslint-config-nodejs'],
},

{
files: ['*.test.ts'],
rules: {
'import/no-nodejs-modules': 'off',
},
extends: [
'@metamask/eslint-config-nodejs',
'@metamask/eslint-config-mocha',
],
},
],

Expand All @@ -36,4 +39,4 @@ module.exports = {
'docs/',
'.yarn/',
],
}
};
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.DS_Store
dist/
docs/

# Logs
logs
*.log
Expand Down
8 changes: 8 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// All of these are defaults except singleQuote, but we specify them
// for explicitness
module.exports = {
quoteProps: 'as-needed',
singleQuote: true,
tabWidth: 2,
trailingComma: 'all',
};
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
eth-ledger-bridge-keyring [![CircleCI](https://circleci.com/gh/MetaMask/eth-ledger-bridge-keyring.svg?style=svg)](https://circleci.com/gh/MetaMask/eth-ledger-bridge-keyring)
==================
# eth-ledger-bridge-keyring [![CircleCI](https://circleci.com/gh/MetaMask/eth-ledger-bridge-keyring.svg?style=svg)](https://circleci.com/gh/MetaMask/eth-ledger-bridge-keyring)

An implementation of MetaMask's [Keyring interface](https://github.com/MetaMask/eth-simple-keyring#the-keyring-class-protocol), that uses a Ledger hardware wallet for all cryptographic operations.

Expand All @@ -16,17 +15,15 @@ device. However there are a number of differences:

- Because extensions have limited access to browser features, there's no easy way to interact wth the Ledger Hardware wallet from the MetaMask extension. This library implements a workaround to those restrictions by injecting (on demand) an iframe to the background page of the extension, (which is hosted [here](https://metamask.github.io/eth-ledger-bridge-keyring/index.html).

The iframe is allowed to interact with the Ledger device (since U2F requires SSL and the iframe is hosted under https) using the libraries from [LedgerJS](https://github.com/LedgerHQ/ledgerjs) *hw-app-eth* and *hw-transport-u2f* and establishes a two-way communication channel with the extension via postMessage.
The iframe is allowed to interact with the Ledger device (since U2F requires SSL and the iframe is hosted under https) using the libraries from [LedgerJS](https://github.com/LedgerHQ/ledgerjs) _hw-app-eth_ and _hw-transport-u2f_ and establishes a two-way communication channel with the extension via postMessage.

The iframe code it's hosted in the same repo under the branch [gh-pages](https://github.com/MetaMask/eth-ledger-bridge-keyring/tree/gh-pages) and it's being served via github pages. In the future we might move it under the metamask.io domain.

Usage
-----
## Usage

In addition to all the known methods from the [Keyring class protocol](https://github.com/MetaMask/eth-simple-keyring#the-keyring-class-protocol),
there are a few others:


- **isUnlocked** : Returns true if we have the public key in memory, which allows to generate the list of accounts at any time

- **unlock** : Connects to the Ledger device and exports the extended public key, which is later used to read the available ethereum addresses inside the Ledger account.
Expand All @@ -41,16 +38,14 @@ there are a few others:

- **forgetDevice** : removes all the device info from memory so the next interaction with the keyring will prompt the user to connect the Ledger device and export the account information

Testing
-------
## Testing

Run the following command:

```bash
yarn test
```

## Attributions


Attributions
-------
This code was inspired by [eth-ledger-keyring](https://github.com/jamespic/eth-ledger-keyring) and [eth-hd-keyring](https://github.com/MetaMask/eth-hd-keyring)
Loading