@marinade.finance/ledger-utils
Advanced tools
Comparing version 2.0.7 to 2.0.8
{ | ||
"name": "@marinade.finance/ledger-utils", | ||
"version": "2.0.7", | ||
"version": "2.0.8", | ||
"description": "Utility functions for interacting with the Ledger from CLI", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -32,2 +32,3 @@ import Solana from '@ledgerhq/hw-app-solana'; | ||
private static findByPubkey; | ||
private static generateAllCombinations; | ||
/** | ||
@@ -34,0 +35,0 @@ * Signing versioned transaction message with ledger |
@@ -82,3 +82,3 @@ "use strict"; | ||
} | ||
let transport; | ||
let transport = undefined; | ||
if (pubkey === undefined) { | ||
@@ -92,16 +92,54 @@ // taking first device | ||
for (const device of ledgerDevices) { | ||
transport = await hw_transport_node_hid_noevents_1.default.open(device.path); | ||
const solanaApi = new hw_app_solana_1.default(transport); | ||
const tempTransport = await hw_transport_node_hid_noevents_1.default.open(device.path); | ||
const solanaApi = new hw_app_solana_1.default(tempTransport); | ||
const ledgerPubkey = await LedgerWallet.getPublicKey(solanaApi, derivedPath); | ||
if (ledgerPubkey.equals(pubkey)) { | ||
transport = tempTransport; | ||
break; // the last found transport is the one we need | ||
} | ||
} | ||
throw new Error('Available ledger devices does not provide pubkey ' + | ||
pubkey.toBase58() + | ||
' for derivation path ' + | ||
derivedPath); | ||
if (transport === undefined) { | ||
// let's do some heuristic search, currently up to 25 | ||
const upTo = 25; | ||
const derivedPathLength = derivedPath.split('/').length - 2; // 44'/501'/<number> | ||
const allCombinations = LedgerWallet.generateAllCombinations(upTo, derivedPathLength); | ||
for (const device of ledgerDevices) { | ||
const tempTransport = await hw_transport_node_hid_noevents_1.default.open(device.path); | ||
for (const combination of allCombinations) { | ||
const derivedPath = exports.SOLANA_LEDGER_BIP44_BASE_PATH + combination.join('/'); | ||
const solanaApi = new hw_app_solana_1.default(tempTransport); | ||
const ledgerPubkey = await LedgerWallet.getPublicKey(solanaApi, derivedPath); | ||
if (ledgerPubkey.equals(pubkey)) { | ||
console.log(`Using derived path ${derivedPath}, pubkey ${pubkey.toBase58()}`); | ||
transport = tempTransport; | ||
break; // the last found transport is the one we need | ||
} | ||
} | ||
} | ||
} | ||
if (transport === undefined) { | ||
throw new Error('Available ledger devices does not provide pubkey ' + | ||
pubkey.toBase58() + | ||
' for derivation path ' + | ||
derivedPath); | ||
} | ||
} | ||
return new hw_app_solana_1.default(transport); | ||
} | ||
static generateAllCombinations(max, maxLength) { | ||
const combinations = []; | ||
function generate(prefix, remainingLength) { | ||
if (remainingLength === 0) { | ||
combinations.push(prefix); | ||
return; | ||
} | ||
for (let i = 0; i <= max; i++) { | ||
generate([...prefix, i], remainingLength - 1); | ||
} | ||
} | ||
for (let length = 1; length <= maxLength; length++) { | ||
generate([], length); | ||
} | ||
return combinations; | ||
} | ||
/** | ||
@@ -108,0 +146,0 @@ * Signing versioned transaction message with ledger |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24611
357