-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for Trezor hardware wallet
- Loading branch information
1 parent
26d254e
commit 6edecbb
Showing
35 changed files
with
1,303 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,16 @@ export interface Configs { | |
API_KEY: string; | ||
} | ||
|
||
// this API key is limited and | ||
// it is only for test purpose | ||
/* | ||
* this API key is limited and | ||
* it is only for test purpose | ||
*/ | ||
const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32'; | ||
export const WC_PROJECT_ID = 'e24844c5deb5193c1c14840a7af6a40b'; | ||
export const TREZOR_MANIFEST = { | ||
appUrl: 'https://widget.rango.exchange/', | ||
email: '[email protected]', | ||
}; | ||
|
||
let configs: Configs = { | ||
API_KEY: RANGO_PUBLIC_API_KEY, | ||
|
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 +1,5 @@ | ||
export const WC_PROJECT_ID = 'e24844c5deb5193c1c14840a7af6a40b'; | ||
export const TREZOR_MANIFEST = { | ||
appUrl: 'https://widget.rango.exchange/', | ||
email: '[email protected]', | ||
}; |
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,4 +1,9 @@ | ||
export const WC_PROJECT_ID = 'e24844c5deb5193c1c14840a7af6a40b'; | ||
export const TREZOR_MANIFEST = { | ||
appUrl: 'https://widget.rango.exchange/', | ||
email: '[email protected]', | ||
}; | ||
|
||
export const swaps = { | ||
EVM: { | ||
from: 'BSC.USDC.0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d', | ||
|
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,14 +1,16 @@ | ||
import type { ProviderInterface } from '@rango-dev/wallets-react'; | ||
import type { WalletType } from '@rango-dev/wallets-shared'; | ||
import type { WalletType, WalletTypes } from '@rango-dev/wallets-shared'; | ||
|
||
import { WalletTypes } from '@rango-dev/wallets-shared'; | ||
|
||
export const isWalletConnectExcluded = ( | ||
selectedProviders?: (WalletType | ProviderInterface)[] | ||
) => | ||
selectedProviders && | ||
!selectedProviders.find((provider) => | ||
typeof provider === 'string' | ||
? provider === WalletTypes.WALLET_CONNECT_2 | ||
: provider.getWalletInfo([]).name === 'WalletConnect' | ||
export const isWalletExcluded = ( | ||
providers: (WalletType | ProviderInterface)[], | ||
wallet: { name: string; type: WalletTypes } | ||
) => { | ||
return ( | ||
providers.length && | ||
!providers.find((provider) => | ||
typeof provider === 'string' | ||
? provider === wallet.type | ||
: provider.getWalletInfo([]).name === wallet.name | ||
) | ||
); | ||
}; |
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
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,33 @@ | ||
{ | ||
"name": "@rango-dev/provider-trezor", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"type": "module", | ||
"source": "./src/index.ts", | ||
"main": "./dist/index.js", | ||
"exports": { | ||
".": "./dist/index.js" | ||
}, | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"scripts": { | ||
"build": "node ../../scripts/build/command.mjs --path wallets/provider-trezor", | ||
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json", | ||
"clean": "rimraf dist", | ||
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'", | ||
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore" | ||
}, | ||
"dependencies": { | ||
"@rango-dev/wallets-shared": "^0.34.1-next.4", | ||
"rango-types": "^0.1.59", | ||
"@trezor/connect-web": "^9.2.4", | ||
"ethers": "^6.11.1", | ||
"@rango-dev/signer-evm": "^0.27.2-next.1" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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 @@ | ||
# @rango-dev/provider-trezor |
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,58 @@ | ||
import { cleanEvmError } from '@rango-dev/signer-evm'; | ||
import { ETHEREUM_CHAIN_ID, Networks } from '@rango-dev/wallets-shared'; | ||
|
||
export const ETHEREUM_BIP32_PATH = "m/44'/60'/0'/0/0"; | ||
|
||
export function getTrezorErrorMessage(error: any) { | ||
if (error?.shortMessage) { | ||
/* | ||
* Some error signs have lengthy, challenging-to-read messages. | ||
* shortMessage is used because it is shorter and easier to understand. | ||
*/ | ||
return new Error(error.shortMessage, { cause: error }); | ||
} | ||
return cleanEvmError(error); | ||
} | ||
|
||
export function getTrezorInstance() { | ||
/* | ||
* Instances have a required property which is `chainId` and is using in swap execution. | ||
* Here we are setting it as Ethereum always since we are supporting only eth for now. | ||
*/ | ||
const instances = new Map(); | ||
|
||
instances.set(Networks.ETHEREUM, { chainId: ETHEREUM_CHAIN_ID }); | ||
|
||
return instances; | ||
} | ||
|
||
export async function getEthereumAccounts(path: string): Promise<{ | ||
accounts: string[]; | ||
chainId: string; | ||
}> { | ||
const { default: TrezorConnect } = await import('@trezor/connect-web'); | ||
const result = await TrezorConnect.ethereumGetAddress({ | ||
path, | ||
}); | ||
|
||
if (!result.success) { | ||
throw new Error(result.payload.error); | ||
} | ||
|
||
return { | ||
accounts: [result.payload.address], | ||
chainId: ETHEREUM_CHAIN_ID, | ||
}; | ||
} | ||
|
||
/* | ||
* Using BigInt in the valueToHex function ensures that the function | ||
* can handle very large integer values that exceed the range of standard JavaScript number types. | ||
*/ | ||
export const valueToHex = (value: string) => { | ||
const ZERO_BIGINT = BigInt(0); | ||
const HEX_BASE = 16; | ||
return BigInt(value) > ZERO_BIGINT | ||
? `0x${BigInt(value).toString(HEX_BASE)}` | ||
: '0x0'; | ||
}; |
Oops, something went wrong.