Ledger Stellar app API
Usage
import Transport from "@ledgerhq/hw-transport-node-hid";
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',
startingBalance: '11.331',
}))
.build();
const transport = await Transport.create();
const str = new Str(transport);
const result = await str.signTransaction("44'/148'/0'", transaction.signatureBase());
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')));
Github,
API Doc,
Ledger Devs Slack