Skip to content

Commit

Permalink
chore: refactor ledger wallet strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
billyjacoby committed Oct 4, 2024
1 parent a16a7b2 commit 5a8e8bf
Show file tree
Hide file tree
Showing 25 changed files with 8,152 additions and 149 deletions.
3 changes: 2 additions & 1 deletion etc/replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const isESM = process.env.BUILD_MODE.includes('esm')

const REPLACEMENT_PAIRS = [
{
path: './src/strategies/wallet-strategy/strategies/Ledger/Base.ts',
// path: './src/strategies/wallet-strategy/strategies/Ledger/Base.ts',
path: './src/strategies/Ledger/Base.ts',
cjs: '@ledgerhq/hw-app-eth/lib/services/ledger',
esm: '@ledgerhq/hw-app-eth/lib-es/services/ledger',
},
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"npmClient": "yarn",
"name": "injective-ts",
"packages": ["packages/*"],
"packages": ["packages/*", "packages/wallets/*"],
"version": "independent",
"useWorkspaces": true,
"command": {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"repository": "https://github.com/InjectiveLabs/injective-ts",
"workspaces": {
"packages": [
"packages/*"
"packages/*",
"packages/wallets/*"
]
},
"scripts": {
Expand Down
9 changes: 2 additions & 7 deletions packages/wallet-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
},
"scripts": {
"postinstall": "link-module-alias",
"build:cjs": "BUILD_MODE=cjs node ./../../etc/replacements.js && tsc --build tsconfig.build.json",
"build:esm": "BUILD_MODE=esm node ./../../etc/replacements.js && tsc --build tsconfig.build.esm.json",
"build:cjs": "BUILD_MODE=cjs tsc --build tsconfig.build.json",
"build:esm": "BUILD_MODE=esm tsc --build tsconfig.build.esm.json",
"build": "yarn build:esm && yarn build:cjs && yarn build:post && link-module-alias",
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && yarn build:post && link-module-alias",
"build:post": "shx cp ../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../etc/stub/package.esm.json.stub dist/esm/package.json",
Expand All @@ -47,11 +47,6 @@
"@injectivelabs/utils": "^1.14.13",
"@keplr-wallet/cosmos": "^0.12.71",
"@keplr-wallet/types": "^0.12.71",
"@ledgerhq/hw-app-cosmos": "^6.29.5",
"@ledgerhq/hw-app-eth": "6.35.6",
"@ledgerhq/hw-transport": "6.30.4",
"@ledgerhq/hw-transport-webhid": "6.28.4",
"@ledgerhq/hw-transport-webusb": "6.28.4",
"@metamask/eth-sig-util": "^4.0.0",
"@solana/wallet-adapter-wallets": "0.19.30",
"@toruslabs/torus-embed": "^1.39.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ import Leap from './strategies/Leap'
import Ninji from './strategies/Ninji'
import Trezor from './strategies/Trezor'
import PrivateKey from './strategies/PrivateKey'
import LedgerLive from './strategies/Ledger/LedgerLive'
import LedgerLegacy from './strategies/Ledger/LedgerLegacy'
import Torus from './strategies/Torus'
import Phantom from './strategies/Phantom'
import Okx from './strategies/Okx'
import BitGet from './strategies/BitGet'
import Cosmostation from './strategies/Cosmostation'
import LedgerCosmos from './strategies/LedgerCosmos'
import WalletConnect from './strategies/WalletConnect'
import { Wallet, WalletDeviceType } from '../../types/enums'
import { isEthWallet, isCosmosWallet } from './utils'
Expand Down Expand Up @@ -86,10 +83,6 @@ const createStrategy = ({
return new Metamask(ethWalletArgs)
case Wallet.TrustWallet:
return new TrustWallet(ethWalletArgs)
case Wallet.Ledger:
return new LedgerLive(ethWalletArgs)
case Wallet.LedgerLegacy:
return new LedgerLegacy(ethWalletArgs)
case Wallet.Trezor:
return new Trezor(ethWalletArgs)
case Wallet.Torus:
Expand All @@ -114,8 +107,6 @@ const createStrategy = ({
return new Keplr({ ...args })
case Wallet.Cosmostation:
return new Cosmostation({ ...args })
case Wallet.LedgerCosmos:
return new LedgerCosmos({ ...args })
case Wallet.Leap:
return new Leap({ ...args })
case Wallet.Ninji:
Expand Down
13 changes: 0 additions & 13 deletions packages/wallet-ts/src/strategies/wallet-strategy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,12 @@ export interface WindowWithLedgerSupport extends Window {
Websocket?: any
}

export interface LedgerWalletInfo {
address: string
baseDerivationPath: string
derivationPath: string
hdKey?: HDNode
publicKey?: string
}

export interface TrezorWalletInfo {
address: string
hdKey: HDNode
derivationPath: string
}

export enum LedgerDerivationPathType {
LedgerLive = 'ledger-live',
LedgerMew = 'ledger-mew',
}

export interface SendTransactionOptions {
address: string
chainId: ChainId
Expand Down
Empty file.
76 changes: 76 additions & 0 deletions packages/wallets/wallet-ledger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@injectivelabs/wallet-ledger",
"description": "Ledger wallet strategy for use with @injectivelabs/wallet-ts.",
"version": "1.14.13",
"sideEffects": false,
"author": {
"name": "InjectiveLabs",
"email": "[email protected]"
},
"license": "Apache-2.0",
"types": "dist/cjs/index.d.ts",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"files": [
"dist"
],
"_moduleAliases": {
"~wallet-ts": "dist"
},
"scripts": {
"postinstall": "link-module-alias",
"build:cjs": "BUILD_MODE=cjs node ./../../../etc/replacements.js && tsc --build tsconfig.build.json",
"build:esm": "BUILD_MODE=esm node ./../../../etc/replacements.js && tsc --build tsconfig.build.esm.json",
"build": "yarn build:esm && yarn build:cjs && yarn build:post && link-module-alias",
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && yarn build:post && link-module-alias",
"build:post": "shx cp ../../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../../etc/stub/package.esm.json.stub dist/esm/package.json",
"clean": "tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.esm.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache && shx mkdir -p dist",
"test": "jest",
"test:watch": "jest --watch",
"test:ci": "jest --coverage --ci --reporters='jest-junit'",
"coverage": "jest --coverage",
"coverage:show": "live-server coverage",
"dev": "ts-node -r tsconfig-paths/register src/index.ts",
"start": "node dist/index.js"
},
"dependencies": {
"@ethereumjs/common": "^3.1.1",
"@ethereumjs/tx": "^4.1.1",
"@injectivelabs/exceptions": "^1.14.13",
"@injectivelabs/networks": "^1.14.13",
"@injectivelabs/sdk-ts": "^1.14.13",
"@injectivelabs/ts-types": "^1.14.13",
"@injectivelabs/utils": "^1.14.13",
"@injectivelabs/wallet-ts": "^1.14.13",
"@ledgerhq/hw-app-cosmos": "^6.29.5",
"@ledgerhq/hw-app-eth": "6.35.6",
"@ledgerhq/hw-transport": "6.30.4",
"@ledgerhq/hw-transport-webhid": "6.28.4",
"@ledgerhq/hw-transport-webusb": "6.28.4",
"alchemy-sdk": "^2.6.3",
"eip1193-provider": "^1.0.1",
"eth-sig-util": "^3.0.1",
"ethereumjs-util": "^7.1.0",
"ethers": "^6.5.1",
"hdkey": "^2.0.1",
"link-module-alias": "^1.2.0",
"long": "^5.2.1",
"shx": "^0.3.3"
},
"devDependencies": {
"@types/eth-sig-util": "^2.1.1",
"@types/ethereumjs-util": "^6.1.0",
"@types/hdkey": "^2.0.1",
"@types/ledgerhq__hw-transport-webusb": "^4.70.1"
},
"gitHead": "35bd09035587be3fd170cc48b5c13f231e699a79",
"typedoc": {
"entryPoint": "./src/index.ts",
"readmeFile": "./README.md",
"displayName": "wallet-ledger API Documentation"
},
"resolutions": {
"**/libsodium": "npm:@bangjelkoski/noop",
"**/libsodium-wrappers": "npm:@bangjelkoski/noop"
}
}
Loading

0 comments on commit 5a8e8bf

Please sign in to comment.