Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _watchdogCallback() {
console.log(`Hardwallet<${this.uid}> Watchdog: state='${this.state}' busy='${this.busy}'`)
if(!this.transport) {
try {
const transport = await Transport.open(this.descriptor);
const str = new Str(transport);
this.transport = transport;
this.str = str;
console.info(`Hardwallet<${this.uid}>: Transport open.`)
} catch(e) {
console.warn(`Hardwallet<${this.uid}> Watchdog: recovering from error... (${e.message})`)
return; // Skip the rest try again later.
}
}
let newState;
try {
if(this.subaccount) {
if(!this.publicKey && !this.busy) await this.selectSubaccount(this.subaccount)
if(!this.busy) await this.ping();
newState = HWW_STATE.READY;
throw new Error(
`Non-ledger key sent to ledger handler: ${JSON.stringify(
key.publicKey,
)}`,
);
}
/*
There's a naive way to do this (to keep all functions stateless and
make the connection anew each time), and there's some way of weaving state
into this.
Gonna do the naive thing first and then figure out how to do this right.
*/
const transport = await LedgerTransport.create(60 * 1000);
const ledgerApi = new LedgerStr(transport);
const result = await ledgerApi.signTransaction(
key.path,
transaction.signatureBase(),
);
const keyPair = StellarSdk.Keypair.fromPublicKey(key.publicKey);
const decoratedSignature = new StellarSdk.xdr.DecoratedSignature({
hint: keyPair.signatureHint(),
signature: result.signature,
});
transaction.signatures.push(decoratedSignature);
return Promise.resolve(transaction);
},
};
.then(transport => new AppStellar(transport))
.then(app => app.signTransaction(this.bip32Path, transaction.signatureBase()))
logInWithLedger: async (bip32Path) => {
try {
const transport = await Transport.create();
const ledgerApp = new AppStellar(transport);
const connectionResult = await ledgerApp.getPublicKey(bip32Path);
this.setupLedgerError = null;
const keypair = StellarSdk.Keypair.fromPublicKey(connectionResult.publicKey);
return this.handlers.logIn(keypair, {
authType: 'ledger',
bip32Path,
});
} catch (error) {
this.setupLedgerError = error.message;
if (error && error.errorCode) {
const u2fErrorCodes = {
0: 'OK',
1: 'OTHER_ERROR',
2: 'BAD_REQUEST',
3: 'CONFIGURATION_UNSUPPORTED',
4: 'DEVICE_INELIGIBLE',
.then(transport => new AppStellar(transport))
.then(app => app.getAppConfiguration())