UNPKG

@secux/transport

Version:

SecuX Hardware Wallet transport API for communication layer

93 lines (89 loc) 3.16 kB
/*! Copyright 2022 SecuX Technology Inc Copyright Chen Wei-En Copyright Wu Tsung-Yu Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /// <reference types="node" /> import { DeviceType, IAPDUResponse, TransportConfig } from "./interface"; import { communicationData } from "@secux/utility/lib/communication"; export { ITransport, IAPDUResponse }; /** * Middle layer between device and application */ declare abstract class ITransport { #private; static readonly PROTOCOLv1 = 1; static readonly PROTOCOLv2 = 2; static deviceType: DeviceType; static mcuVersion: string; static seVersion: string; OnNotification?: (data: Buffer) => void; autoApplyL1: boolean; /** * @constructor * @param {object} config */ constructor(config?: TransportConfig); /** * Connect to Secux Device */ Connect(): Promise<void>; /** * Disconnect from Secux Device */ Disconnect(): Promise<void>; /** * Write data to SecuX device * @param {Buffer} data */ Write(data: Buffer): Promise<void>; get Read(): () => Promise<Buffer>; get ReceiveData(): (data: Buffer) => void; get Exchange(): (data: Buffer) => Promise<Buffer>; get Send(): (cla: number, ins: number, p1?: number, p2?: number, data?: Buffer) => Promise<IAPDUResponse>; getAddress(path: string, ...args: any[]): Promise<string>; getPublickey(path: string, ...args: any[]): Promise<string>; getXPublickey(path: string, ...args: any[]): Promise<string>; sign(...args: any[]): Promise<any>; signWithImage(imageName: string, imageData: communicationData, metadata: any, ...args: any[]): Promise<{ raw_tx: any; signature: any; }>; get version(): number; set version(value: number); get packetSize(): number; set packetSize(value: number); get CustomerId(): string; get DeviceType(): string; get DeviceId(): string; get Model(): string; get MCU(): string; get SE(): string; } export declare function staticImplements<T>(): <U extends T>(constructor: U) => void; export interface IPlugin { getAddress(this: ITransport, path: string, ...args: any[]): Promise<string>; getPublickey(this: ITransport, path: string, ...args: any[]): Promise<string>; getXPublickey(this: ITransport, path: string, ...args: any[]): Promise<string>; sign(this: ITransport, ...args: any[]): Promise<{ raw_tx: string; signature?: string; } | { signature: string; } | { multi_command: Array<communicationData>; }>; } /** * @deprecated */ export declare function loadPlugin(plugin: Function, name: string): void;