@ledgerhq/hw-app-str
TypeScript icon, indicating that this package has built-in type declarations

6.27.19 • Public • Published

Ledger Stellar app API

Usage

// when using "@ledgerhq/hw-transport-node-hid" library you need to go to
// Settings -> Browser support in ledger stellar app and set this setting to 'No'
import Transport from "@ledgerhq/hw-transport-node-hid";
// import Transport from "@ledgerhq/hw-transport-u2f"; // for browser
import Str from "@ledgerhq/hw-app-str";
import StellarSdk from "stellar-sdk";

const getStrAppVersion = async () => {
    const transport = await Transport.create();
    const str = new Str(transport);
    const result = await str.getAppConfiguration();
    return result.version;
}
getStrAppVersion().then(v => console.log(v));

const getStrPublicKey = async () => {
  const transport = await Transport.create();
  const str = new Str(transport);
  const result = await str.getPublicKey("44'/148'/0'");
  return result.publicKey;
};
let publicKey;
getStrPublicKey().then(pk => {
    console.log(pk);
    publicKey = pk;
});

const signStrTransaction = async (publicKey) => {
  const transaction = new StellarSdk.TransactionBuilder({accountId: () => publicKey, sequenceNumber: () => '1234', incrementSequenceNumber: () => null})
    .addOperation(StellarSdk.Operation.createAccount({
       source: publicKey,
       destination: 'GBLYVYCCCRYTZTWTWGOMJYKEGQMTH2U3X4R4NUI7CUGIGEJEKYD5S5OJ', // SATIS5GR33FXKM7HVWZ2UQO33GM66TVORZUEF2HPUQ3J7K634CTOAWQ7
       startingBalance: '11.331',
    }))
    .build();
  const transport = await Transport.create();
  const str = new Str(transport);
  const result = await str.signTransaction("44'/148'/0'", transaction.signatureBase());
  
  // add signature to transaction
  const keyPair = StellarSdk.Keypair.fromPublicKey(publicKey);
  const hint = keyPair.signatureHint();
  const decorated = new StellarSdk.xdr.DecoratedSignature({hint: hint, signature: result.signature});
  transaction.signatures.push(decorated);
  
  return transaction;
}
signStrTransaction(publicKey).then(transaction => console.log(transaction.toEnvelope().toXDR().toString('base64')));

Are you adding Ledger support to your software wallet?

You may be using this package to communicate with the Stellar Nano App.

For a smooth and quick integration:

  • See the developers’ documentation on the Developer Portal and
  • Go on Discord to chat with developer support and the developer community.

Package Sidebar

Install

DownloadsWeekly Downloads

2,062

Version

6.27.19

License

Apache-2.0

Unpacked Size

83.6 kB

Total Files

25

Last publish

Collaborators

  • crema-ledger
  • chrisd-ledger
  • gbrahm-ledger
  • sergii-shkolin
  • yogh
  • haammar-ledger
  • kvn-ledger
  • ofreyssinet
  • jelbaz-ledger
  • achabrolin-ledger
  • gre
  • btchip
  • meriadec
  • flocks
  • juan-cortes
  • val_pinkman
  • iammorrow
  • phenry-ledger
  • jdecussy-ledger
  • junsugiura
  • hzheng_ledger