mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
Merge pull request #29249 from danwbyrne/ledger-transports
adds typings for 3 '@LedgerHQ' Transport packages
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
// Type definitions for @ledgerhq/hw-transport-node-hid 4.22
|
||||
// Project: https://github.com/LedgerHQ/ledgerjs/tree/master/packages/hw-transport-node-hid
|
||||
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types = "node"/>
|
||||
import HID = require("node-hid");
|
||||
import Transport from "@ledgerhq/hw-transport";
|
||||
|
||||
declare class TransportNodeHid extends Transport {
|
||||
constructor(
|
||||
device: HID.HID,
|
||||
ledgerTransport?: boolean,
|
||||
timeout?: number
|
||||
);
|
||||
static open(path: string): Promise<TransportNodeHid>;
|
||||
setScrambleKey(): void;
|
||||
|
||||
device: HID.HID;
|
||||
ledgerTransport: boolean;
|
||||
timeout: number;
|
||||
exchangeStack: any[];
|
||||
}
|
||||
|
||||
export default TransportNodeHid;
|
||||
@@ -0,0 +1,19 @@
|
||||
import Transport from "@ledgerhq/hw-transport-node-hid";
|
||||
|
||||
// $ExpectType Promise<boolean>
|
||||
Transport.isSupported();
|
||||
// $ExpectType Promise<ReadonlyArray<string>>
|
||||
Transport.list();
|
||||
// $ExpectType Promise<TransportNodeHid>
|
||||
Transport.open("test");
|
||||
|
||||
const test = Transport.open("test").then(transport => {
|
||||
// $ExpectType void
|
||||
transport.setScrambleKey();
|
||||
|
||||
// $ExpectType Promise<Buffer>
|
||||
transport.exchange(Buffer.from("test", "hex"));
|
||||
|
||||
// $ExpectType Promise<void>
|
||||
transport.close();
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@ledgerhq/hw-transport": ["ledgerhq__hw-transport"],
|
||||
"@ledgerhq/hw-transport-node-hid": [
|
||||
"ledgerhq__hw-transport-node-hid"
|
||||
]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "ledgerhq__hw-transport-node-hid-tests.ts"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// Type definitions for @ledgerhq/hw-transport-u2f 4.21
|
||||
// Project: https://github.com/LedgerHQ/ledgerjs/tree/master/packages/hw-transport-u2f
|
||||
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="node" />
|
||||
import Transport from "@ledgerhq/hw-transport";
|
||||
|
||||
declare class TransportU2F extends Transport {
|
||||
constructor();
|
||||
static open(_: any, _openTimeout?: number): Promise<TransportU2F>;
|
||||
}
|
||||
|
||||
export default TransportU2F;
|
||||
@@ -0,0 +1,19 @@
|
||||
import Transport from "@ledgerhq/hw-transport-u2f";
|
||||
|
||||
// $ExpectType Promise<boolean>
|
||||
Transport.isSupported();
|
||||
// $ExpectType Promise<ReadonlyArray<string>>
|
||||
Transport.list();
|
||||
// $ExpectType Promise<TransportU2F>
|
||||
Transport.open("test");
|
||||
|
||||
const test = Transport.open('test').then(transport => {
|
||||
// $ExpectType void
|
||||
transport.setScrambleKey('BTC');
|
||||
|
||||
// $ExpectType Promise<Buffer>
|
||||
transport.exchange(Buffer.from("test", "hex"));
|
||||
|
||||
// $ExpectType Promise<void>
|
||||
transport.close();
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@ledgerhq/hw-transport": ["ledgerhq__hw-transport"],
|
||||
"@ledgerhq/hw-transport-u2f": ["ledgerhq__hw-transport-u2f"]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "ledgerhq__hw-transport-u2f-tests.ts"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
// Type definitions for @ledgerhq/hw-transport 4.21
|
||||
// Project: https://github.com/LedgerHQ/ledgerjs/tree/master/packages/hw-transport
|
||||
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
declare class Transport<TDescriptor extends Descriptor = string> {
|
||||
constructor();
|
||||
static isSupported(): Promise<boolean>;
|
||||
static list(): Promise<ReadonlyArray<Descriptor>>;
|
||||
static listen(
|
||||
observer: Observer<DescriptorEvent<Descriptor>>
|
||||
): Subscription;
|
||||
static open(
|
||||
descriptor: Descriptor,
|
||||
timeout?: number
|
||||
): Promise<Transport<typeof descriptor>>;
|
||||
static create(
|
||||
openTimeout?: number,
|
||||
listenTimeout?: number
|
||||
): Promise<Transport<Descriptor>>;
|
||||
exchange(apdu: Buffer): Promise<Buffer>;
|
||||
setScrambleKey(key: string): void;
|
||||
close(): Promise<void>;
|
||||
on(eventName: string, cb: any): void;
|
||||
off(eventName: string, cb: any): void;
|
||||
setDebugMode(debug: boolean | ((log: string) => void)): void;
|
||||
setExchangeTimeout(exchangeTimeout: number): void;
|
||||
send(cla: number, ins: number, p1: number, p2: number, data: Buffer, statusList: ReadonlyArray<number>): Promise<Buffer>;
|
||||
}
|
||||
|
||||
export type Device = any;
|
||||
export type Descriptor = string; // ?
|
||||
export interface DescriptorEvent<Descriptor> {
|
||||
type: "add" | "remove";
|
||||
descriptor: Descriptor;
|
||||
device?: Device;
|
||||
}
|
||||
export interface Observer<Ev> {
|
||||
readonly next: (event: Ev) => any;
|
||||
readonly error: (e: any) => any;
|
||||
readonly complete: () => any;
|
||||
}
|
||||
export interface Subscription {
|
||||
readonly unsubscribe: () => void;
|
||||
}
|
||||
export function getAltStatusMessage(code: number): string;
|
||||
export const StatusCodes: {[k in string]: number};
|
||||
|
||||
export default Transport;
|
||||
@@ -0,0 +1,19 @@
|
||||
import Transport from "@ledgerhq/hw-transport";
|
||||
|
||||
// $ExpectType Promise<boolean>
|
||||
Transport.isSupported();
|
||||
// $ExpectType Promise<ReadonlyArray<string>>
|
||||
Transport.list();
|
||||
// $ExpectType Promise<Transport<string>>
|
||||
Transport.open("test");
|
||||
|
||||
const test = Transport.open("test").then(transport => {
|
||||
// $ExpectType void
|
||||
transport.setScrambleKey('test');
|
||||
|
||||
// $ExpectType Promise<Buffer>
|
||||
transport.exchange(Buffer.from("test", "hex"));
|
||||
|
||||
// $ExpectType Promise<void>
|
||||
transport.close();
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@ledgerhq/hw-transport": ["ledgerhq__hw-transport"]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "ledgerhq__hw-transport-tests.ts"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user