Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for generating type declarations during build #2

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
}