Skip to content

Commit

Permalink
Merge pull request #2 from t4top/type-support
Browse files Browse the repository at this point in the history
Add support for generating type declarations during build
  • Loading branch information
nerdvibe authored Mar 5, 2024
2 parents 98f4258 + 50cc787 commit ef8768d
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { MinaLedgerJS } from "./lib";
export * from "./types";
39 changes: 39 additions & 0 deletions dist/lib.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { SignTransactionArgs, Transport, SignTransactionResponse, GetAddressResponse, GetAppVersionResponse, GetAppNameResponse } from "./types";
/**
* Mina App API
*/
export declare class MinaLedgerJS {
transport: Transport;
constructor(transport: Transport, scrambleKey?: string);
protected pad(n: number | string, width?: number, paddingValue?: number | string): string;
protected asciiToHex(str: string): string;
protected convertMemo(memo: string): string;
protected createTXApdu({ txType, senderAccount, senderAddress, receiverAddress, amount, fee, nonce, validUntil, memo, networkId, }: SignTransactionArgs): string;
/**
* Get Mina address for a given account number.
*
* @param account int of the account number
* @param display optionally enable or not the display
* @return an object with a publicKey
* @example
* const result = await Mina.getAddress(1);
* const { publicKey, returnCode } = result;
*/
getAddress(account?: number): Promise<GetAddressResponse>;
signTransaction({ txType, senderAccount, senderAddress, receiverAddress, amount, fee, nonce, validUntil, memo, networkId, }: SignTransactionArgs): Promise<SignTransactionResponse>;
/**
* get the version of the Mina app installed on the hardware device
* the version is returned from the installed app.
*
* @return an object with a version
*/
getAppVersion(): Promise<GetAppVersionResponse>;
/**
* get the name and version of the Mina app installed on the hardware device
* it can be used to ping the app and know the name of the running app.
* The name and version is returned from the Ledger firmware.
*
* @return an object with an app name and version
*/
getAppName(): Promise<GetAppNameResponse>;
}
61 changes: 61 additions & 0 deletions dist/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Buffer } from "buffer/";
/**
* Transport mechanism.
* @see https://github.com/LedgerHQ/ledgerjs for all transport Available
*/
export interface Transport {
/**
* Used in U2F to avoid different web apps to communicate with different ledger implementations
* @param {string} key
*/
setScrambleKey(key: string): void;
/**
* sends data to Ledger
* @param {number} cla
* @param {number} ins
* @param {number} p1
* @param {number} p2
* @param {Buffer} data
* @param {number[]} statusList Allowed status list.
* @returns {Promise<Buffer>}
*/
send(cla: number, ins: number, p1: number, p2: number, data?: Buffer, statusList?: number[]): Promise<Buffer>;
}
export interface SignTransactionArgs {
txType: number;
senderAccount: number;
senderAddress: string;
receiverAddress: string;
amount: number;
fee: number;
nonce: number;
validUntil?: number;
memo?: string;
networkId: number;
}
export interface BaseLedgerResponse {
returnCode: string;
statusText?: string;
message?: string;
}
export interface GetAddressResponse extends BaseLedgerResponse {
publicKey?: string;
}
export interface SignTransactionResponse extends BaseLedgerResponse {
signature?: string;
}
export interface GetAppVersionResponse extends BaseLedgerResponse {
version?: string;
}
export interface GetAppNameResponse extends BaseLedgerResponse {
name?: string;
version?: string;
}
export declare enum Networks {
MAINNET = 1,
DEVNET = 0
}
export declare enum TxType {
PAYMENT = 0,
DELEGATION = 4
}
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
},
"homepage": "https://github.com/nerdvibe/mina-ledger-js",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/index.js",
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nerdvibe/mina-ledger-js.git"
Expand All @@ -26,7 +33,7 @@
},
"scripts": {
"start": "ts-node-dev src/index.ts",
"build": "tsc --outDir dist/",
"build": "tsc --outDir dist/ --declaration",
"test": "echo \"No test specified for now\""
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"allowSyntheticDefaultImports": true,
"lib": ["es2020", "dom"]
},
"exclude": ["node_modules", "example"]
"exclude": ["node_modules", "example", "dist"]
}

0 comments on commit ef8768d

Please sign in to comment.