Skip to content

Commit

Permalink
fix example code in packages/hw-app-str/README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratniex committed Apr 25, 2018
1 parent 444cf95 commit 2e11147
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/hw-app-str/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@


```js
// 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();
Expand All @@ -24,23 +27,33 @@ const getStrPublicKey = async () => {
const result = await str.getPublicKey("44'/148'/0'");
return result.publicKey;
};
getStrPublicKey().then(pk => console.log(pk));

const signStrTransaction = async () => {
const transaction = ...;
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: signature});
const decorated = new StellarSdk.xdr.DecoratedSignature({hint: hint, signature: result.signature});
transaction.signatures.push(decorated);

return transaction;
}
signStrTransaction().then(s => console.log(s.toString('hex')));
signStrTransaction(publicKey).then(transaction => console.log(transaction.toEnvelope().toXDR().toString('base64')));
```


Expand Down

0 comments on commit 2e11147

Please sign in to comment.