-
-
Notifications
You must be signed in to change notification settings - Fork 650
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
Electron TREZOR Support #1946
Merged
Merged
Electron TREZOR Support #1946
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
029030c
Type trezor connect.
wbobeirne c4b2f65
Check in trezor code
wbobeirne d6e82dc
Merge develop and enclave back up
wbobeirne bfb2dac
Implement TREZOR wallet
wbobeirne 1bdfd56
Resolve conflict in signTransaction handler
wbobeirne 5120621
Convert TREZOR to use enclave class like Ledger.
wbobeirne 826e5bf
Switch to mycrypto fork of trezor lib. Remove unused dependencies.
wbobeirne 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
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
declare module 'vendor/trezor-connect' { | ||
type Path = number[] | string; | ||
|
||
interface TxSignature { | ||
r: number; | ||
s: string; | ||
v: string; | ||
} | ||
|
||
interface MessageSignature { | ||
signature: string; | ||
address: string; | ||
} | ||
|
||
interface PublicKey { | ||
xpubkey: string; | ||
path: string; | ||
serializedPath: string; | ||
chainCode: string; | ||
publicKey: string; | ||
} | ||
|
||
interface ErrorResponse { | ||
success: false; | ||
error: string; | ||
} | ||
type SuccessResponse<T> = { | ||
success: true; | ||
error: undefined; | ||
} & T; | ||
type Response<T> = ErrorResponse | SuccessResponse<T>; | ||
|
||
namespace TrezorConnect { | ||
export function getXPubKey( | ||
path: Path, | ||
cb: (res: Response<PublicKey>) => void, | ||
minFirmware?: string | ||
): void; | ||
|
||
export function ethereumSignTx( | ||
path: Path, | ||
nonce: string, | ||
gasPrice: string, | ||
gasLimit: string, | ||
to: string, | ||
value: string, | ||
data: string | null, | ||
chainId: number | null, | ||
cb: (signature: Response<TxSignature>) => void, | ||
minFirmware?: string | ||
): void; | ||
|
||
export function signMessage( | ||
path: Path, | ||
message: string, | ||
cb: (res: Response<MessageSignature>) => void, | ||
coin?: string, | ||
minFirmware?: string | ||
): void; | ||
|
||
export function ethereumGetAddress( | ||
path: Path, | ||
cb: (res: Response<{ address: string }>) => void, | ||
minFirmware?: string | ||
): void; | ||
} | ||
|
||
export default TrezorConnect; | ||
} |
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,191 @@ | ||
/* tslint:disable max-classes-per-file */ | ||
// Types are only based off of what's mentioned in the API | ||
// https://github.com/trezor/trezor.js/blob/master/API.md | ||
|
||
declare module 'trezor.js' { | ||
import { EventEmitter } from 'events'; | ||
import { Transport, TrezorDeviceInfoWithSession as DeviceDescriptor } from 'trezor-link'; | ||
|
||
/***************/ | ||
/* Device List */ | ||
/***************/ | ||
|
||
export interface DeviceListOptions { | ||
debug?: boolean; | ||
debugInfo?: boolean; | ||
transport?: Transport; | ||
nodeTransport?: Transport; | ||
configUrl?: string; | ||
config?: string; | ||
bridgeVersionUrl?: string; | ||
clearSession?: boolean; | ||
clearSessionTime?: number; | ||
rememberDevicePasshprase?: boolean; | ||
// Unsure of these options or our need for them | ||
// getPassphraseHash?(device: Device): number[] | undefined; | ||
// xpubDerive?: (xpub: string, network: bitcoin.Network, index: number) => Promise<string>; | ||
} | ||
|
||
export class DeviceList extends EventEmitter { | ||
public transport: Transport | undefined; | ||
public devices: { [k: string]: Device }; | ||
public unacquiredDevices: { [k: string]: UnacquiredDevice }; | ||
constructor(opts?: DeviceListOptions); | ||
public acquireFirstDevice( | ||
rejectOnEmpty?: boolean | ||
): Promise<{ device: Device; session: Session }>; | ||
} | ||
|
||
/**********/ | ||
/* Device */ | ||
/**********/ | ||
|
||
export interface CoinType { | ||
coin_name: string; | ||
coin_shortcut: string; | ||
address_type: number; | ||
maxfee_kb: number; | ||
address_type_p2sh: number; | ||
} | ||
|
||
export interface Features { | ||
vendor: string; | ||
major_version: number; | ||
minor_version: number; | ||
patch_version: number; | ||
bootloader_mode: boolean; | ||
device_id: string; | ||
pin_protection: boolean; | ||
passphrase_protection: boolean; | ||
language: string; | ||
label: string; | ||
coins: CoinType[]; | ||
initialized: boolean; | ||
revision: string; | ||
bootloader_hash: string; | ||
imported: boolean; | ||
pin_cached: boolean; | ||
passphrase_cached: boolean; | ||
needs_backup?: boolean; | ||
firmware_present?: boolean; | ||
flags?: number; | ||
model?: string; | ||
unfinished_backup?: boolean; | ||
} | ||
|
||
export interface RunOptions { | ||
aggressive?: boolean; | ||
skipFinalReload?: boolean; | ||
waiting?: boolean; | ||
onlyOneActivity?: boolean; | ||
} | ||
|
||
export class Device extends EventEmitter { | ||
public path: string; | ||
public features: Features; | ||
|
||
constructor( | ||
transport: Transport, | ||
descriptor: DeviceDescriptor, | ||
features: Features, | ||
deviceList: DeviceList | ||
); | ||
|
||
public isBootloader(): boolean; | ||
public isInitialized(): boolean; | ||
public getVersion(): string; | ||
public atLeast(v: string): boolean; | ||
public isUsed(): boolean; | ||
public isUsedHere(): boolean; | ||
public isUsedElsewhere(): boolean; | ||
|
||
public run<T>(fn: (session: Session) => Promise<T> | T, options?: RunOptions): Promise<T>; | ||
public waitForSessionAndRun<T>( | ||
fn: (session: Session) => Promise<T> | T, | ||
options?: RunOptions | ||
): Promise<T>; | ||
public steal(): Promise<boolean>; | ||
} | ||
|
||
/*********************/ | ||
/* Unacquired Device */ | ||
/*********************/ | ||
|
||
export class UnacquiredDevice extends EventEmitter { | ||
public path: string; | ||
constructor(transport: Transport, descriptor: DeviceDescriptor, deviceList: DeviceList); | ||
public steal(): Promise<boolean>; | ||
} | ||
|
||
/***********/ | ||
/* Session */ | ||
/***********/ | ||
|
||
export interface MessageResponse<T> { | ||
type: string; | ||
message: T; | ||
} | ||
|
||
export interface EthereumSignature { | ||
v: number; | ||
r: string; | ||
s: string; | ||
} | ||
|
||
export interface HDPubNode { | ||
depth: number; | ||
fingerprint: number; | ||
child_num: number; | ||
chain_code: string; | ||
public_key: string; | ||
} | ||
|
||
export interface PublicKey { | ||
node: HDPubNode; | ||
xpub: string; | ||
} | ||
|
||
export type DefaultMessageResponse = MessageResponse<object>; | ||
|
||
export class Session extends EventEmitter { | ||
public typedCall<T>(type: string, resType: string, message: T): Promise<T>; | ||
public getEntropy(size: number): Promise<MessageResponse<{ bytes: string }>>; | ||
public ethereumGetAddress( | ||
path: number[], | ||
display?: boolean | ||
): Promise<MessageResponse<{ address: string; path: number[] }>>; | ||
public clearSession(): Promise<boolean>; | ||
public signEthMessage( | ||
path: number[], | ||
message: string | ||
): Promise<MessageResponse<{ address: string; signature: string }>>; | ||
public verifyEthMessage(address: string, signature: string, message: string): Promise<boolean>; | ||
public signEthTx( | ||
path: number[], | ||
nonce: string, | ||
gasPrice: string, | ||
gasLimit: string, | ||
to: string, | ||
value: string, | ||
data?: string, | ||
chainId?: number | ||
): Promise<EthereumSignature>; | ||
public getPublicKey( | ||
path: number[], | ||
coin?: string | CoinType | ||
): Promise<MessageResponse<PublicKey>>; | ||
|
||
/* Unused functions, either Bitcoin-centric or just things we wouldn't want to touch */ | ||
// public getAddress(path: number[], coin: string | CoinType, display: boolean): Promise<MessageResponse<{ address: string }>>; | ||
// public verifyAddress(path: number[], refAddress: string, coin: string | CoinType): Promise<boolean>; | ||
// public getHDNode(path: number[], coin: string | CoinType): Promise<HDNode>; | ||
// public wipeDevice(): Promise<boolean>; | ||
// public resetDevice(...): Promise<boolean>; | ||
// public loadDevice(...): Promise<boolean>; | ||
// public recoverDevice(...): Promise<boolean>; | ||
// public updateFirmware(payload: string): Promise<boolean>; | ||
// public signMessage(path: number[], message: string, coin: string | CoinType, segwit: boolean): Promise<object>; | ||
// public verifyMessage(...): Promise<boolean>; | ||
// public signIdentity(...): any; | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to make a class that extends HardwareWallet that does this for you. @HenryNguyen5 how would you suggest this best be done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably just make a utility HOF instead that does the branching for you