generated from MetaMask/metamask-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add OneKey keyring #353
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
Open
Akaryatrh
wants to merge
20
commits into
main
Choose a base branch
from
feat/onekey-keyring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ec02eda
feat: support onekey
ByteZhang1024 be93f69
feat: sofe derive
ByteZhang1024 7bd08e8
feat: update jd sdk
ByteZhang1024 8648ef2
feat: update jd sdk
ByteZhang1024 cbc7a7d
feat: update jd sdk
ByteZhang1024 f8dc1e0
fix: build
ByteZhang1024 04710f6
feat: add error tip
ByteZhang1024 deea5da
chore: add test case
ByteZhang1024 a18c779
chore: fix lint
ByteZhang1024 a621908
fix: index error
ByteZhang1024 f7e6591
chore: add get pubkey catch
ByteZhang1024 3e52ac6
chore: adjust jest config
ByteZhang1024 a4bb524
fix: get passphrase state error
ByteZhang1024 8dab699
chore: fix typo
ByteZhang1024 cc191ea
fix: lint
ByteZhang1024 532ba69
fix: review
ByteZhang1024 e4453a3
fix: code review
ByteZhang1024 7cd0f44
fix: lint
ByteZhang1024 2c8529e
Merge remote-tracking branch 'origin/main' into feat/onekey-keyring
Akaryatrh 2d94f20
feat: update yarn lock after main merge
Akaryatrh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
feat: support onekey
- Loading branch information
commit ec02eda2bfe52f186e078a2c7290ce9ce89e8e93
There are no files selected for viewing
This file contains hidden or 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,15 @@ | ||
| ISC License | ||
|
|
||
| Copyright (c) 2020 MetaMask | ||
|
|
||
| Permission to use, copy, modify, and/or distribute this software for any | ||
| purpose with or without fee is hereby granted, provided that the above | ||
| copyright notice and this permission notice appear in all copies. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains hidden or 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,41 @@ | ||
| # eth-onekey-bridge-keyring | ||
|
|
||
| An implementation of MetaMask's [Keyring interface](https://github.com/MetaMask/eth-simple-keyring#the-keyring-class-protocol), that uses a OneKey hardware wallet for all cryptographic operations. | ||
|
|
||
| In most regards, it works in the same way as | ||
| [eth-hd-keyring](https://github.com/MetaMask/eth-hd-keyring), but using a OneKey | ||
| device. However there are a number of differences: | ||
|
|
||
| - Because the keys are stored in the device, operations that rely on the device | ||
| will fail if there is no OneKey device attached, or a different OneKey device | ||
| is attached. | ||
|
|
||
| - It does not support the `signMessage`, `signTypedData` or `exportAccount` | ||
| methods, because OneKey devices do not support these operations. | ||
|
|
||
| - Because extensions have limited access to browser features, there's no easy way to interact wth the OneKey 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, | ||
|
|
||
| ## 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 OneKey device and exports the extended public key, which is later used to read the available ethereum addresses inside the OneKey account. | ||
|
|
||
| - **setAccountToUnlock** : the index of the account that you want to unlock in order to use with the signTransaction and signPersonalMessage methods | ||
|
|
||
| - **getFirstPage** : returns the first ordered set of accounts from the OneKey account | ||
|
|
||
| - **getNextPage** : returns the next ordered set of accounts from the OneKey account based on the current page | ||
|
|
||
| - **getPreviousPage** : returns the previous ordered set of accounts from the OneKey account based on the current page | ||
|
|
||
| - **forgetDevice** : removes all the device info from memory so the next interaction with the keyring will prompt the user to connect the OneKey device and export the account information | ||
|
|
||
| ## Testing and Linting | ||
|
|
||
| Run `yarn test` to run the tests once. To run tests on file changes, run `yarn test:watch`. | ||
|
|
||
| Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues. |
This file contains hidden or 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,32 @@ | ||
| /* | ||
| * For a detailed explanation regarding each configuration property and type check, visit: | ||
| * https://jestjs.io/docs/configuration | ||
| */ | ||
|
|
||
| const merge = require('deepmerge'); | ||
| const path = require('path'); | ||
|
|
||
| const baseConfig = require('../../jest.config.packages'); | ||
|
|
||
| const displayName = path.basename(__dirname); | ||
|
|
||
| module.exports = merge(baseConfig, { | ||
| // The display name when running multiple projects | ||
| displayName, | ||
|
|
||
| // An array of regexp pattern strings used to skip coverage collection | ||
| coveragePathIgnorePatterns: ['./src/tests'], | ||
|
|
||
| // The glob patterns Jest uses to detect test files | ||
| testMatch: ['**/*.test.[jt]s?(x)'], | ||
|
|
||
| // An object that configures minimum threshold enforcement for coverage results | ||
| coverageThreshold: { | ||
| global: { | ||
| branches: 52.38, | ||
| functions: 91.22, | ||
| lines: 90.15, | ||
| statements: 90.35, | ||
| }, | ||
| }, | ||
| }); |
This file contains hidden or 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,107 @@ | ||
| { | ||
| "name": "@metamask/eth-onekey-keyring", | ||
| "version": "1.0.0", | ||
| "description": "A MetaMask compatible keyring, for onekey hardware wallets", | ||
| "keywords": [ | ||
| "ethereum", | ||
| "keyring", | ||
| "onekey", | ||
| "metamask" | ||
| ], | ||
| "homepage": "https://github.com/MetaMask/accounts/blob/main/packages/keyring-eth-onekey/README.md", | ||
| "bugs": { | ||
| "url": "https://github.com/MetaMask/accounts/issues" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/MetaMask/accounts.git" | ||
| }, | ||
| "license": "ISC", | ||
| "exports": { | ||
| ".": { | ||
| "import": { | ||
| "types": "./dist/index.d.mts", | ||
| "default": "./dist/index.mjs" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
| } | ||
| }, | ||
| "main": "./dist/index.cjs", | ||
| "types": "./dist/index.d.cts", | ||
| "files": [ | ||
| "dist/" | ||
| ], | ||
| "scripts": { | ||
| "build": "ts-bridge --project tsconfig.build.json --no-references", | ||
| "build:clean": "yarn build --clean", | ||
| "build:docs": "typedoc", | ||
| "changelog:update": "../../scripts/update-changelog.sh @metamask/eth-trezor-keyring", | ||
| "changelog:validate": "../../scripts/validate-changelog.sh @metamask/eth-trezor-keyring", | ||
| "publish:preview": "yarn npm publish --tag preview", | ||
| "test": "jest && jest-it-up", | ||
| "test:clean": "jest --clearCache", | ||
| "test:watch": "jest --watch" | ||
| }, | ||
| "dependencies": { | ||
| "@ethereumjs/tx": "^5.4.0", | ||
| "@ethereumjs/util": "^9.1.0", | ||
| "@metamask/eth-sig-util": "^8.2.0", | ||
| "@metamask/utils": "^11.1.0", | ||
| "@noble/hashes": "^1.7.0", | ||
| "@onekeyfe/hd-core": "^1.1.1", | ||
| "@onekeyfe/hd-shared": "^1.1.1", | ||
| "@onekeyfe/hd-transport": "^1.1.1", | ||
| "@onekeyfe/hd-web-sdk": "^1.1.1", | ||
| "bytebuffer": "^5.0.1", | ||
| "tslib": "^2.6.2" | ||
| }, | ||
| "devDependencies": { | ||
| "@ethereumjs/common": "^4.4.0", | ||
| "@lavamoat/allow-scripts": "^3.2.1", | ||
| "@lavamoat/preinstall-always-fail": "^2.1.0", | ||
| "@metamask/auto-changelog": "^3.4.4", | ||
| "@metamask/keyring-utils": "workspace:^", | ||
| "@ts-bridge/cli": "^0.6.3", | ||
| "@types/ethereumjs-tx": "^1.0.1", | ||
| "@types/jest": "^29.5.12", | ||
| "@types/node": "^20.12.12", | ||
| "@types/sinon": "^17.0.3", | ||
| "@types/w3c-web-usb": "^1.0.6", | ||
| "deepmerge": "^4.2.2", | ||
| "depcheck": "^1.4.7", | ||
| "ethereumjs-tx": "^1.3.7", | ||
| "jest": "^29.5.0", | ||
| "jest-environment-jsdom": "^29.7.0", | ||
| "jest-it-up": "^3.1.0", | ||
| "sinon": "^19.0.2", | ||
| "ts-jest": "^29.0.5", | ||
| "ts-node": "^10.9.2", | ||
| "typedoc": "^0.25.13", | ||
| "typescript": "~5.6.3" | ||
| }, | ||
| "engines": { | ||
| "node": "^18.18 || >=20" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public", | ||
| "registry": "https://registry.npmjs.org/" | ||
| }, | ||
| "installConfig": { | ||
| "hoistingLimits": "workspaces" | ||
| }, | ||
| "lavamoat": { | ||
| "allowScripts": { | ||
| "@lavamoat/preinstall-always-fail": false, | ||
| "ethereumjs-tx>ethereumjs-util>keccak": false, | ||
| "ethereumjs-tx>ethereumjs-util>secp256k1": false, | ||
| "hdkey>secp256k1": false, | ||
| "ethereumjs-tx>ethereumjs-util>ethereum-cryptography>keccak": false, | ||
| "ethereumjs-tx>ethereumjs-util>ethereum-cryptography>secp256k1": false, | ||
| "@onekeyfe/hd-core>@onekeyfe/hd-transport>protobufjs": false, | ||
| "@onekeyfe/hd-web-sdk>@onekeyfe/hd-core>@onekeyfe/hd-transport>protobufjs": false | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 @@ | ||
| export const ONEKEY_HARDWARE_UI_EVENT = 'onekey-hardware-ui-event'; |
This file contains hidden or 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,4 @@ | ||
| export * from './onekey-keyring'; | ||
| export type * from './onekey-bridge'; | ||
| export * from './onekey-web-bridge'; | ||
| export * from './constants'; |
This file contains hidden or 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,67 @@ | ||
| /* eslint-disable @typescript-eslint/no-redundant-type-constituents */ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| /* eslint-disable @typescript-eslint/naming-convention */ | ||
Akaryatrh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import type { | ||
| ConnectSettings, | ||
| Params, | ||
| EVMSignedTx, | ||
| EVMSignTransactionParams, | ||
| EVMSignMessageParams, | ||
| EVMSignTypedDataParams, | ||
| EVMGetPublicKeyParams, | ||
| Features, | ||
| } from '@onekeyfe/hd-core'; | ||
| import type { EthereumMessageSignature } from '@onekeyfe/hd-transport'; | ||
|
|
||
| type Unsuccessful = { | ||
| success: false; | ||
| payload: { | ||
| error: string; | ||
| code?: string | number; | ||
| }; | ||
| }; | ||
| type Success<T> = { | ||
| success: true; | ||
| payload: T; | ||
| }; | ||
| type Response<T> = Promise<Success<T> | Unsuccessful>; | ||
|
|
||
| export type OneKeyBridge = { | ||
| model?: string; | ||
|
|
||
| on(event: string, callback: (event: any) => void): void; | ||
|
|
||
| off(event: string): void; | ||
|
|
||
| init(settings: Partial<ConnectSettings>): Promise<void>; | ||
|
|
||
| dispose(): Promise<void>; | ||
|
|
||
| updateTransportMethod(transportType: string): Promise<void>; | ||
|
|
||
| getDeviceFeatures(): Response<Features>; | ||
|
|
||
| // OneKeySdk.getPublicKey has two overloads | ||
| // It is not possible to extract them from the library using utility types | ||
| getPublicKey( | ||
| params: Params<EVMGetPublicKeyParams>, | ||
| ): Response<{ publicKey: string; chainCode: string }>; | ||
|
|
||
| batchGetPublicKey( | ||
| params: Params<any> & { bundle: EVMGetPublicKeyParams[] }, | ||
| ): Response<{ pub: string }[]>; | ||
|
|
||
| getPassphraseState(): Response<string | undefined>; | ||
|
|
||
| ethereumSignTransaction( | ||
| params: Params<EVMSignTransactionParams>, | ||
| ): Response<EVMSignedTx>; | ||
|
|
||
| ethereumSignMessage( | ||
| params: Params<EVMSignMessageParams>, | ||
| ): Response<EthereumMessageSignature>; | ||
|
|
||
| ethereumSignTypedData( | ||
| params: Params<EVMSignTypedDataParams>, | ||
| ): Response<EthereumMessageSignature>; | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.