hw-app-iota
v0.6.5
Published
Ledger Hardware Wallet IOTA Application API
Downloads
32
Readme
hw-app-iota
JS Library for communication with Ledger Hardware Wallets and the IOTA Ledger Application.
Examples
Basic example
import Transport from "@ledgerhq/hw-transport-node-hid";
// import Transport from "@ledgerhq/hw-transport-u2f"; // for browser
import Iota from 'hw-app-iota';
const getAddress = async () => {
const transport = await Transport.create();
const iota = new Iota(transport);
await iota.setActiveSeed("44'/4218'/0'/0'");
return await iota.getAddress(0, {checksum: true});
};
getAddress().then(a => console.log(a));
Transaction example
import Transport from "@ledgerhq/hw-transport-node-hid";
// import Transport from "@ledgerhq/hw-transport-u2f"; // for browser
import Iota from 'hw-app-iota';
const prepareTransfers = async () => {
const transport = await Transport.create();
const iota = new Iota(transport);
await iota.setActiveSeed("44'/4218'/0'/0'");
const transfers = [{
address: 'ANADDRESS',
value: 10000,
tag: 'ATAG'
}];
const inputs = [{
address: 'INPUTADDRESS',
balance: 10000,
keyIndex: 4
}];
return await iota.prepareTransfers(transfers, inputs);
};
prepareTransfers().then(t => console.log(t));
See also
API Reference
hw-app-iota~Iota
Class for the interaction with the Ledger IOTA application.
- ~Iota
- .setActiveSeed(path, [security])
- .getAddress(index, [options]) ⇒ Promise.<String>
- .prepareTransfers(transfers, inputs, [remainder], [now]) ⇒ Promise.<Array.<String>>
- .getAppVersion() ⇒ Promise.<String>
- .getAppMaxBundleSize() ⇒ Promise.<Integer>
iota.setActiveSeed(path, [security])
Prepares the IOTA seed to be used for subsequent calls.
| Param | Type | Default | Description | | --- | --- | --- | --- | | path | String | | String representation of the BIP32 path. At most 5 levels. | | [security] | Integer | 2 | IOTA security level to use |
Example
iota.setActiveSeed("44'/4218'/0'/0'", 2);
iota.getAddress(index, [options]) ⇒ Promise.<String>
Generates an address index-based. The result depends on the initalized seed and security level.
Returns: Promise.<String> - Tryte-encoded address
| Param | Type | Default | Description | | --- | --- | --- | --- | | index | Integer | | Index of the address | | [options] | Object | | | | [options.checksum] | Boolean | false | Append 9 tryte checksum | | [options.display] | Boolean | false | Display generated address on display |
Example
iota.getAddress(0, { checksum: true });
iota.prepareTransfers(transfers, inputs, [remainder], [now]) ⇒ Promise.<Array.<String>>
Prepares the array of raw transaction data (trytes) by generating a bundle and signing the inputs.
Returns: Promise.<Array.<String>> - Transaction trytes of 2673 trytes per transaction
| Param | Type | Default | Description | | --- | --- | --- | --- | | transfers | Array.<Object> | | Transfer objects | | transfers[].address | String | | Tryte-encoded address of recipient, with or without the 9 tryte checksum | | transfers[].value | Integer | | Value to be transferred | | transfers[].tag | String | | Tryte-encoded tag. Maximum value is 27 trytes. | | inputs | Array.<Object> | | Inputs used for funding the transfer | | inputs[].address | String | | Tryte-encoded source address, with or without the 9 tryte checksum | | inputs[].balance | Integer | | Balance of that input | | inputs[].keyIndex | String | | Index of the address | | [inputs[].tags] | Array.<String> | | Tryte-encoded tags, one for each security level. | | [remainder] | Object | | Destination for sending the remainder value (of the inputs) to. | | remainder.address | String | | Tryte-encoded address, with or without the 9 tryte checksum | | remainder.keyIndex | Integer | | Index of the address | | [remainder.tag] | String | | Tryte-encoded tag. Maximum value is 27 trytes. | | [now] | function | Date.now() | Function to get the milliseconds since the UNIX epoch for timestamps. |
iota.getAppVersion() ⇒ Promise.<String>
Retrieves version information about the installed application from the device.
Returns: Promise.<String> - Semantic Version string (i.e. MAJOR.MINOR.PATCH)
iota.getAppMaxBundleSize() ⇒ Promise.<Integer>
Retrieves the largest supported number of transactions (including meta transactions) in one transfer bundle from the device.
Returns: Promise.<Integer> - Maximum bundle size