Skip to content

Commit 959c73b

Browse files
authored
Full conversion to typescript (#5)
* Full conversion to typescript * Fix export logic * README fixes * Version bump to 1.1.0 While this looks like a significant change, the code is semantically the same as before getAddress is a typo and has been renamed to the correct getPublicKey. I'm the only user of this repo at this time and I'll be changing all references to the correct one when updating to this version so I consider this all a minor change. Breaking change: - getAddress is now getPublicKey (which is what it should've been in the first place)
1 parent 3ff86d9 commit 959c73b

36 files changed

+1864
-338
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules/
1+
node_modules/
2+
coverage

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Ledger Hardware Wallet Kaspa JavaScript bindings.
1414
* [Kaspa](#kaspa)
1515
* [Parameters](#parameters)
1616
* [Examples](#examples)
17-
* [getAddress](#getaddress)
17+
* [getPublicKey](#getaddress)
1818
* [Parameters](#parameters-1)
1919
* [Examples](#examples-1)
2020
* [signTransaction](#signtransaction)
@@ -32,13 +32,13 @@ Kaspa API
3232
#### Examples
3333

3434
```javascript
35-
import Kaspa from "@ledgerhq/hw-app-kaspa";
35+
import Kaspa from "hw-app-kaspa";
3636
const kaspa = new Kaspa(transport);
3737
```
3838

39-
#### getAddress
39+
#### getPublicKey
4040

41-
Get Kaspa address (public key) for a BIP32 path.
41+
Get Kaspa Public Key for a BIP32 path.
4242

4343
##### Parameters
4444

@@ -48,10 +48,10 @@ Get Kaspa address (public key) for a BIP32 path.
4848
##### Examples
4949

5050
```javascript
51-
kaspa.getAddress("44'/111111'/0'").then(r => r.address)
51+
kaspa.getPublicKey("44'/111111'/0'")
5252
```
5353

54-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{address: [Buffer](https://nodejs.org/api/buffer.html)}>** an object with the address field
54+
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** the public key buffer with chain code
5555

5656
#### signTransaction
5757

@@ -63,9 +63,9 @@ Sign a Kaspa transaction.
6363

6464
##### Examples
6565

66-
```javascript
67-
const Kaspa = require("../src/kaspa");
68-
const { TransactionInput, TransactionOutput, Transaction } = require("../src/transaction");
66+
```typescript
67+
import Kaspa from 'hw-app-kaspa';
68+
import { TransactionInput, TransactionOutput, Transaction } from 'hw-app-kaspa';
6969

7070
...
7171

index.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

jest.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
preset: "ts-jest",
3+
testEnvironment: "node",
4+
testRegex: ".test.ts$",
5+
collectCoverage: true,
6+
testPathIgnorePatterns: ["packages/*/lib-es", "packages/*/lib"],
7+
coveragePathIgnorePatterns: ["packages/create-dapp"],
8+
passWithNoTests: true,
9+
rootDir: __dirname,
10+
};

lib-es/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Kaspa from './kaspa';
2+
export { TransactionInput, TransactionOutput, Transaction } from './transaction';
3+
export default Kaspa;
4+
//# sourceMappingURL=index.d.ts.map

lib-es/index.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib-es/index.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib-es/index.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib-es/kaspa.d.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/// <reference types="node" />
2+
import Transport from "@ledgerhq/hw-transport";
3+
import { Transaction } from "./transaction";
4+
declare class Kaspa {
5+
/**
6+
* @type {Transport}
7+
*/
8+
transport: Transport;
9+
constructor(transport: Transport);
10+
/**
11+
* Get Kaspa address (public key) for a BIP32 path.
12+
*
13+
* @param {string} path a BIP32 path
14+
* @param {boolean} display flag to show display
15+
* @returns {Buffer} an object with the address field
16+
*
17+
* @example
18+
* kaspa.getPublicKey("44'/111111'/0'").then(r => r.address)
19+
*/
20+
getPublicKey(path: any, display?: boolean): Promise<Buffer>;
21+
/**
22+
* Sign a Kaspa transaction. Applies the signatures into the input objects
23+
*
24+
* @param {Transaction} transaction - the Transaction object
25+
*
26+
*
27+
* @example
28+
* kaspa.signTransaction(transaction)
29+
*/
30+
signTransaction(transaction: Transaction): Promise<void>;
31+
/**
32+
* Sign personal message on the device
33+
* @param {String} message - the personal message string to sign. Max 120 len for Nano S, 200 len for others
34+
* @param {0|1} addressType
35+
* @param {number} addressIndex
36+
*
37+
* @returns {Buffer} application config object
38+
*
39+
* @example
40+
* kaspa.signMessage(message).then(r => r.version)
41+
*/
42+
signMessage(message: string, addressType: 0 | 1, addressIndex: number): Promise<{
43+
signature: string;
44+
messageHash: string;
45+
}>;
46+
/**
47+
* Get application configuration.
48+
*
49+
* @returns {Buffer} application config object
50+
*
51+
* @example
52+
* kaspa.getVersion().then(r => r.version)
53+
*/
54+
getVersion(): Promise<{
55+
version: string;
56+
}>;
57+
sendToDevice(instruction: any, p1: any, payload?: Buffer, p2?: number): Promise<Buffer>;
58+
}
59+
export default Kaspa;
60+
//# sourceMappingURL=kaspa.d.ts.map

lib-es/kaspa.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)