Skip to content

Commit

Permalink
Full conversion to typescript (#5)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
coderofstuff authored Dec 26, 2023
1 parent 3ff86d9 commit 959c73b
Show file tree
Hide file tree
Showing 36 changed files with 1,864 additions and 338 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
coverage
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Ledger Hardware Wallet Kaspa JavaScript bindings.
* [Kaspa](#kaspa)
* [Parameters](#parameters)
* [Examples](#examples)
* [getAddress](#getaddress)
* [getPublicKey](#getaddress)
* [Parameters](#parameters-1)
* [Examples](#examples-1)
* [signTransaction](#signtransaction)
Expand All @@ -32,13 +32,13 @@ Kaspa API
#### Examples

```javascript
import Kaspa from "@ledgerhq/hw-app-kaspa";
import Kaspa from "hw-app-kaspa";
const kaspa = new Kaspa(transport);
```

#### getAddress
#### getPublicKey

Get Kaspa address (public key) for a BIP32 path.
Get Kaspa Public Key for a BIP32 path.

##### Parameters

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

```javascript
kaspa.getAddress("44'/111111'/0'").then(r => r.address)
kaspa.getPublicKey("44'/111111'/0'")
```

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
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

#### signTransaction

Expand All @@ -63,9 +63,9 @@ Sign a Kaspa transaction.

##### Examples

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

...

Expand Down
9 changes: 0 additions & 9 deletions index.js

This file was deleted.

10 changes: 10 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
preset: "ts-jest",
testEnvironment: "node",
testRegex: ".test.ts$",
collectCoverage: true,
testPathIgnorePatterns: ["packages/*/lib-es", "packages/*/lib"],
coveragePathIgnorePatterns: ["packages/create-dapp"],
passWithNoTests: true,
rootDir: __dirname,
};
4 changes: 4 additions & 0 deletions lib-es/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Kaspa from './kaspa';
export { TransactionInput, TransactionOutput, Transaction } from './transaction';
export default Kaspa;
//# sourceMappingURL=index.d.ts.map
1 change: 1 addition & 0 deletions lib-es/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib-es/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib-es/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions lib-es/kaspa.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/// <reference types="node" />
import Transport from "@ledgerhq/hw-transport";
import { Transaction } from "./transaction";
declare class Kaspa {
/**
* @type {Transport}
*/
transport: Transport;
constructor(transport: Transport);
/**
* Get Kaspa address (public key) for a BIP32 path.
*
* @param {string} path a BIP32 path
* @param {boolean} display flag to show display
* @returns {Buffer} an object with the address field
*
* @example
* kaspa.getPublicKey("44'/111111'/0'").then(r => r.address)
*/
getPublicKey(path: any, display?: boolean): Promise<Buffer>;
/**
* Sign a Kaspa transaction. Applies the signatures into the input objects
*
* @param {Transaction} transaction - the Transaction object
*
*
* @example
* kaspa.signTransaction(transaction)
*/
signTransaction(transaction: Transaction): Promise<void>;
/**
* Sign personal message on the device
* @param {String} message - the personal message string to sign. Max 120 len for Nano S, 200 len for others
* @param {0|1} addressType
* @param {number} addressIndex
*
* @returns {Buffer} application config object
*
* @example
* kaspa.signMessage(message).then(r => r.version)
*/
signMessage(message: string, addressType: 0 | 1, addressIndex: number): Promise<{
signature: string;
messageHash: string;
}>;
/**
* Get application configuration.
*
* @returns {Buffer} application config object
*
* @example
* kaspa.getVersion().then(r => r.version)
*/
getVersion(): Promise<{
version: string;
}>;
sendToDevice(instruction: any, p1: any, payload?: Buffer, p2?: number): Promise<Buffer>;
}
export default Kaspa;
//# sourceMappingURL=kaspa.d.ts.map
1 change: 1 addition & 0 deletions lib-es/kaspa.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

171 changes: 171 additions & 0 deletions lib-es/kaspa.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib-es/kaspa.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 959c73b

Please sign in to comment.