Display address
This commit is contained in:
parent
b4d8f3617f
commit
3b5dd4ec21
|
@ -96,8 +96,19 @@ export class LedgerWallet extends HardwareWallet implements IFullWallet {
|
|||
}
|
||||
|
||||
public displayAddress() {
|
||||
const path = this.dPath + '/' + this.index;
|
||||
|
||||
if (process.env.BUILD_ELECTRON) {
|
||||
return EnclaveAPI.displayAddress({
|
||||
walletType: WalletTypes.LEDGER,
|
||||
path
|
||||
})
|
||||
.then(res => res.success)
|
||||
.catch(() => false);
|
||||
}
|
||||
|
||||
return this.ethApp
|
||||
.getAddress_async(this.dPath + '/' + this.index, true, false)
|
||||
.getAddress_async(path, true, false)
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,9 @@ import {
|
|||
SignTransactionParams,
|
||||
SignTransactionResponse,
|
||||
SignMessageParams,
|
||||
SignMessageResponse
|
||||
SignMessageResponse,
|
||||
DisplayAddressParams,
|
||||
DisplayAddressResponse
|
||||
} from 'shared/enclave/types';
|
||||
|
||||
const api = {
|
||||
|
@ -26,6 +28,10 @@ const api = {
|
|||
|
||||
signMessage(params: SignMessageParams) {
|
||||
return makeRequest<SignMessageResponse>(EnclaveMethods.SIGN_MESSAGE, params);
|
||||
},
|
||||
|
||||
displayAddress(params: DisplayAddressParams) {
|
||||
return makeRequest<DisplayAddressResponse>(EnclaveMethods.DISPLAY_ADDRESS, params);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
import { getWalletLib } from 'shared/enclave/server/wallets';
|
||||
import { DisplayAddressParams, DisplayAddressResponse } from 'shared/enclave/types';
|
||||
|
||||
export default function(params: DisplayAddressParams): Promise<DisplayAddressResponse> {
|
||||
const wallet = getWalletLib(params.walletType);
|
||||
return wallet.displayAddress(params.path);
|
||||
}
|
|
@ -2,6 +2,7 @@ import getAddresses from './getAddresses';
|
|||
import getChainCode from './getChainCode';
|
||||
import signTransaction from './signTransaction';
|
||||
import signMessage from './signMessage';
|
||||
import displayAddress from './displayAddress';
|
||||
import { EnclaveMethods, EnclaveMethodParams, EnclaveMethodResponse } from 'shared/enclave/types';
|
||||
|
||||
const handlers: {
|
||||
|
@ -12,7 +13,8 @@ const handlers: {
|
|||
[EnclaveMethods.GET_ADDRESSES]: getAddresses,
|
||||
[EnclaveMethods.GET_CHAIN_CODE]: getChainCode,
|
||||
[EnclaveMethods.SIGN_TRANSACTION]: signTransaction,
|
||||
[EnclaveMethods.SIGN_MESSAGE]: signMessage
|
||||
[EnclaveMethods.SIGN_MESSAGE]: signMessage,
|
||||
[EnclaveMethods.DISPLAY_ADDRESS]: displayAddress
|
||||
};
|
||||
|
||||
export default handlers;
|
||||
|
|
|
@ -11,6 +11,10 @@ const KeepKey: WalletLib = {
|
|||
|
||||
async signMessage() {
|
||||
throw new Error('Not yet implemented');
|
||||
},
|
||||
|
||||
async displayAddress() {
|
||||
throw new Error('Not yet implemented');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ async function getEthApp() {
|
|||
const transport = await TransportNodeHid.create();
|
||||
return new LedgerEth(transport);
|
||||
} catch (err) {
|
||||
console.log(err.message);
|
||||
if (err && err.message && err.message.includes('cannot open device with path')) {
|
||||
throw new Error(
|
||||
'Failed to connect with your Ledger. It may be in use with another application. Try plugging the device back in.'
|
||||
|
@ -54,7 +53,7 @@ const Ledger: WalletLib = {
|
|||
};
|
||||
},
|
||||
|
||||
async signMessage(msg: string, path: string) {
|
||||
async signMessage(msg, path) {
|
||||
const app = await getEthApp();
|
||||
const msgHex = Buffer.from(msg).toString('hex');
|
||||
const signed = await app.signPersonalMessage(path, msgHex);
|
||||
|
@ -62,6 +61,20 @@ const Ledger: WalletLib = {
|
|||
return {
|
||||
signedMessage: combined
|
||||
};
|
||||
},
|
||||
|
||||
async displayAddress(path) {
|
||||
try {
|
||||
const app = await getEthApp();
|
||||
await app.getAddress(path, true, false);
|
||||
return {
|
||||
success: true
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
success: false
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -22,6 +22,10 @@ const Trezor: WalletLib = {
|
|||
|
||||
async signMessage() {
|
||||
throw new Error('Not yet implemented');
|
||||
},
|
||||
|
||||
async displayAddress() {
|
||||
throw new Error('Not yet implemented');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@ export enum EnclaveMethods {
|
|||
GET_ADDRESSES = 'get-addresses',
|
||||
GET_CHAIN_CODE = 'get-chain-code',
|
||||
SIGN_TRANSACTION = 'sign-transaction',
|
||||
SIGN_MESSAGE = 'sign-message'
|
||||
SIGN_MESSAGE = 'sign-message',
|
||||
DISPLAY_ADDRESS = 'display-address'
|
||||
}
|
||||
|
||||
export enum WalletTypes {
|
||||
|
@ -64,17 +65,29 @@ export interface SignMessageResponse {
|
|||
signedMessage: string;
|
||||
}
|
||||
|
||||
// Display Address Request
|
||||
export interface DisplayAddressParams {
|
||||
walletType: WalletTypes;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface DisplayAddressResponse {
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
// All Requests & Responses
|
||||
export type EnclaveMethodParams =
|
||||
| GetAddressesParams
|
||||
| GetChainCodeParams
|
||||
| SignTransactionParams
|
||||
| SignMessageParams;
|
||||
| SignMessageParams
|
||||
| DisplayAddressParams;
|
||||
export type EnclaveMethodResponse =
|
||||
| GetAddressesResponse
|
||||
| GetChainCodeResponse
|
||||
| SignTransactionResponse
|
||||
| SignMessageResponse;
|
||||
| SignMessageResponse
|
||||
| DisplayAddressResponse;
|
||||
|
||||
// RPC requests, responses & failures
|
||||
export interface EnclaveSuccessResponse<T = EnclaveMethodResponse> {
|
||||
|
@ -100,4 +113,5 @@ export interface WalletLib {
|
|||
getChainCode(dpath: string): Promise<GetChainCodeResponse>;
|
||||
signTransaction(transaction: RawTransaction, path: string): Promise<SignTransactionResponse>;
|
||||
signMessage(msg: string, path: string): Promise<SignMessageResponse>;
|
||||
displayAddress(path: string): Promise<DisplayAddressResponse>;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue