types.ts
1 // Enclave enums 2 export enum EnclaveMethods { 3 GET_CHAIN_CODE = 'get-chain-code', 4 SIGN_TRANSACTION = 'sign-transaction', 5 SIGN_MESSAGE = 'sign-message', 6 DISPLAY_ADDRESS = 'display-address' 7 } 8 9 export enum WalletTypes { 10 LEDGER = 'ledger', 11 TREZOR = 'trezor', 12 SAFE_T = 'safe-t', 13 KEEPKEY = 'keepkey' 14 } 15 16 export interface RawTransaction { 17 chainId: number; 18 gasLimit: string; 19 gasPrice: string; 20 to: string; 21 nonce: string; 22 data: string; 23 value: string; 24 } 25 26 // Get chain code request 27 export interface GetChainCodeParams { 28 walletType: WalletTypes; 29 dpath: string; 30 } 31 32 export interface GetChainCodeResponse { 33 publicKey: string; 34 chainCode: string; 35 } 36 37 // Sign Transaction Request 38 export interface SignTransactionParams { 39 walletType: WalletTypes; 40 transaction: RawTransaction; 41 path: string; 42 } 43 44 export interface SignTransactionResponse { 45 signedTransaction: string; 46 } 47 48 // Sign Message Request 49 export interface SignMessageParams { 50 walletType: WalletTypes; 51 message: string; 52 path: string; 53 } 54 55 export interface SignMessageResponse { 56 signedMessage: string; 57 } 58 59 // Display Address Request 60 export interface DisplayAddressParams { 61 walletType: WalletTypes; 62 path: string; 63 } 64 65 export interface DisplayAddressResponse { 66 success: boolean; 67 } 68 69 // All Requests & Responses 70 export type EnclaveMethodParams = 71 | GetChainCodeParams 72 | SignTransactionParams 73 | SignMessageParams 74 | DisplayAddressParams; 75 export type EnclaveMethodResponse = 76 | GetChainCodeResponse 77 | SignTransactionResponse 78 | SignMessageResponse 79 | DisplayAddressResponse; 80 81 // RPC requests, responses & failures 82 export interface EnclaveSuccessResponse<T = EnclaveMethodResponse> { 83 data: T; 84 error?: undefined; 85 } 86 87 export interface EnclaveErrorResponse { 88 data?: undefined; 89 error: { 90 code: number; 91 type: string; 92 message: string; 93 }; 94 } 95 96 export type EnclaveResponse<T = EnclaveMethodResponse> = 97 | EnclaveSuccessResponse<T> 98 | EnclaveErrorResponse; 99 100 // Wallet lib 101 export interface WalletLib { 102 getChainCode(dpath: string): Promise<GetChainCodeResponse>; 103 signTransaction(transaction: RawTransaction, path: string): Promise<SignTransactionResponse>; 104 signMessage(msg: string, path: string): Promise<SignMessageResponse>; 105 displayAddress(path: string): Promise<DisplayAddressResponse>; 106 }