Skip to content

Commit ef8768d

Browse files
authored
Merge pull request #2 from t4top/type-support
Add support for generating type declarations during build
2 parents 98f4258 + 50cc787 commit ef8768d

File tree

5 files changed

+111
-2
lines changed

5 files changed

+111
-2
lines changed

dist/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { MinaLedgerJS } from "./lib";
2+
export * from "./types";

dist/lib.d.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { SignTransactionArgs, Transport, SignTransactionResponse, GetAddressResponse, GetAppVersionResponse, GetAppNameResponse } from "./types";
2+
/**
3+
* Mina App API
4+
*/
5+
export declare class MinaLedgerJS {
6+
transport: Transport;
7+
constructor(transport: Transport, scrambleKey?: string);
8+
protected pad(n: number | string, width?: number, paddingValue?: number | string): string;
9+
protected asciiToHex(str: string): string;
10+
protected convertMemo(memo: string): string;
11+
protected createTXApdu({ txType, senderAccount, senderAddress, receiverAddress, amount, fee, nonce, validUntil, memo, networkId, }: SignTransactionArgs): string;
12+
/**
13+
* Get Mina address for a given account number.
14+
*
15+
* @param account int of the account number
16+
* @param display optionally enable or not the display
17+
* @return an object with a publicKey
18+
* @example
19+
* const result = await Mina.getAddress(1);
20+
* const { publicKey, returnCode } = result;
21+
*/
22+
getAddress(account?: number): Promise<GetAddressResponse>;
23+
signTransaction({ txType, senderAccount, senderAddress, receiverAddress, amount, fee, nonce, validUntil, memo, networkId, }: SignTransactionArgs): Promise<SignTransactionResponse>;
24+
/**
25+
* get the version of the Mina app installed on the hardware device
26+
* the version is returned from the installed app.
27+
*
28+
* @return an object with a version
29+
*/
30+
getAppVersion(): Promise<GetAppVersionResponse>;
31+
/**
32+
* get the name and version of the Mina app installed on the hardware device
33+
* it can be used to ping the app and know the name of the running app.
34+
* The name and version is returned from the Ledger firmware.
35+
*
36+
* @return an object with an app name and version
37+
*/
38+
getAppName(): Promise<GetAppNameResponse>;
39+
}

dist/types.d.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Buffer } from "buffer/";
2+
/**
3+
* Transport mechanism.
4+
* @see https://github.com/LedgerHQ/ledgerjs for all transport Available
5+
*/
6+
export interface Transport {
7+
/**
8+
* Used in U2F to avoid different web apps to communicate with different ledger implementations
9+
* @param {string} key
10+
*/
11+
setScrambleKey(key: string): void;
12+
/**
13+
* sends data to Ledger
14+
* @param {number} cla
15+
* @param {number} ins
16+
* @param {number} p1
17+
* @param {number} p2
18+
* @param {Buffer} data
19+
* @param {number[]} statusList Allowed status list.
20+
* @returns {Promise<Buffer>}
21+
*/
22+
send(cla: number, ins: number, p1: number, p2: number, data?: Buffer, statusList?: number[]): Promise<Buffer>;
23+
}
24+
export interface SignTransactionArgs {
25+
txType: number;
26+
senderAccount: number;
27+
senderAddress: string;
28+
receiverAddress: string;
29+
amount: number;
30+
fee: number;
31+
nonce: number;
32+
validUntil?: number;
33+
memo?: string;
34+
networkId: number;
35+
}
36+
export interface BaseLedgerResponse {
37+
returnCode: string;
38+
statusText?: string;
39+
message?: string;
40+
}
41+
export interface GetAddressResponse extends BaseLedgerResponse {
42+
publicKey?: string;
43+
}
44+
export interface SignTransactionResponse extends BaseLedgerResponse {
45+
signature?: string;
46+
}
47+
export interface GetAppVersionResponse extends BaseLedgerResponse {
48+
version?: string;
49+
}
50+
export interface GetAppNameResponse extends BaseLedgerResponse {
51+
name?: string;
52+
version?: string;
53+
}
54+
export declare enum Networks {
55+
MAINNET = 1,
56+
DEVNET = 0
57+
}
58+
export declare enum TxType {
59+
PAYMENT = 0,
60+
DELEGATION = 4
61+
}

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
},
1616
"homepage": "https://github.com/nerdvibe/mina-ledger-js",
1717
"main": "./dist/index.js",
18+
"module": "./dist/index.js",
19+
"types": "./dist/index.d.ts",
20+
"exports": {
21+
"require": "./dist/index.js",
22+
"import": "./dist/index.js",
23+
"types": "./dist/index.d.ts"
24+
},
1825
"repository": {
1926
"type": "git",
2027
"url": "git+https://github.com/nerdvibe/mina-ledger-js.git"
@@ -26,7 +33,7 @@
2633
},
2734
"scripts": {
2835
"start": "ts-node-dev src/index.ts",
29-
"build": "tsc --outDir dist/",
36+
"build": "tsc --outDir dist/ --declaration",
3037
"test": "echo \"No test specified for now\""
3138
},
3239
"dependencies": {

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"allowSyntheticDefaultImports": true,
1111
"lib": ["es2020", "dom"]
1212
},
13-
"exclude": ["node_modules", "example"]
13+
"exclude": ["node_modules", "example", "dist"]
1414
}

0 commit comments

Comments
 (0)