Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async getPublicKey(accountIndex: number): Promise {
if (this.appService.isDesktop()) {
const publicKeyHex: string = this.appService.sendIpcMessageSync('ledger-get-public-key', accountIndex);
if (publicKeyHex.startsWith('Error: ')) {
throw new Error(publicKeyHex);
}
return publicKeyHex;
} else {
const transport = await TransportWebUSB.create();
// todo: move this to a shared fn
const publicKey: Buffer = await transport.exchange(Buffer.from('800400' + this.byteToHex(accountIndex) + '00', 'hex'));
return publicKey.toString('hex').substr(0, 64);
}
}
async connect(timeout = INTERACTION_TIMEOUT) {
// assume well connection if connected once
if (this.cosmosApp) return
const transport = await TransportWebUSB.create(timeout)
const cosmosLedgerApp = new CosmosApp(transport)
this.cosmosApp = cosmosLedgerApp
await this.isSendingData()
await this.isReady()
}
async getCosmosAppVersion() {
export async function createTransport() {
var transport = null;
transport = await TransportWebUSB.create();
console.log('USING WEBUSB');
var qrl = await new Qrl(transport);
return qrl
}
const CardanoLedgerCryptoProvider = async (ADALITE_CONFIG, walletState) => {
let transport
try {
transport = await LedgerTransportU2F.create()
} catch (u2fError) {
try {
transport = await LedgerTransportWebusb.create()
} catch (webUsbError) {
debugLog(webUsbError)
throw u2fError
}
}
transport.setExchangeTimeout(ADALITE_CONFIG.ADALITE_LOGOUT_AFTER * 1000)
const ledger = new Ledger(transport)
const state = Object.assign(walletState, {
derivationScheme: derivationSchemes.v2,
rootHdPassphrase: null,
derivedAddresses: {},
})
const isHwWallet = () => true
const getHwWalletName = () => 'Ledger'
execInQueue(async () => {
const { derivationMode, currency, index: account } = this.props;
try {
const p = transportGlobalP || TransportWebUSB.create();
transportGlobalP = p;
const transport = await p;
const { address, path } = await getAddress(transport, {
currency,
path: runDerivationScheme(
getDerivationScheme({ currency, derivationMode }),
currency,
{ account }
),
derivationMode,
verify
});
this.setState({ address, path });
} catch (error) {
this.setState({ error });
}
public async sign(accountIndex: number, message: string): Promise {
if (this.appService.isDesktop()) {
const signature: string = this.appService.sendIpcMessageSync('ledger-sign', {accountIndex, message});
if (signature.startsWith('Error: ')) {
throw new Error(signature);
}
return signature;
} else {
const transport = await TransportWebUSB.create();
let offset = 0;
while (offset !== message.length) {
let chunk: string;
if (message.length - offset > 510) {
chunk = message.substr(offset, 510);
} else {
chunk = message.substr(offset);
}
let apdu = '8002';
const final = (offset + chunk.length) === message.length;
apdu += final ? '80' : '00';
apdu += this.byteToHex(accountIndex);
apdu += this.byteToHex(chunk.length / 2);
apdu += chunk;
offset += chunk.length;
const result: Buffer = await transport.exchange(Buffer.from(apdu, 'hex'));
open: (id: string): ?Promise<*> => {
if (id.startsWith("webusb")) {
const existingDevice = webusbDevices[id];
return existingDevice
? TransportWebUSB.open(existingDevice)
: TransportWebUSB.create();
}
return null;
},
const getLedgerTransport = async () => {
let transport;
const support = await isWebUsbSupported();
if (support) {
transport = await webUsbTransport.create();
} else {
transport = await u2fTransport.create(OPEN_TIMEOUT, LISTENER_TIMEOUT);
}
return transport;
};
const getLedgerAppConfig = async _ledger => {