Socket
Socket
Sign inDemoInstall

@marinade.finance/ledger-utils

Package Overview
Dependencies
5
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.15 to 2.0.16

10

package.json
{
"name": "@marinade.finance/ledger-utils",
"version": "2.0.15",
"version": "2.0.16",
"description": "Utility functions for interacting with the Ledger from CLI",

@@ -26,14 +26,14 @@ "repository": {

"devDependencies": {
"pino": "^8.15.1",
"@ledgerhq/errors": "^6.13.1",
"@ledgerhq/hw-app-solana": "^7.0.12",
"@ledgerhq/hw-transport-node-hid-noevents": "^6.27.18",
"@solana/web3.js": "^1.78.4"
"@solana/web3.js": "^1.78.4",
"@marinade.finance/ts-common": "^2.0.16"
},
"peerDependencies": {
"pino": "^8.15.1",
"@ledgerhq/errors": "^6.14.0",
"@ledgerhq/hw-app-solana": "^7.0.13",
"@ledgerhq/hw-transport-node-hid-noevents": "^6.27.19",
"@solana/web3.js": "^1.78.4"
"@solana/web3.js": "^1.78.4",
"@marinade.finance/ts-common": "^2.0.16"
},

@@ -40,0 +40,0 @@ "scripts": {

import { Wallet } from './ledger';
import { Logger } from 'pino';
import { LoggerPlaceholder } from '@marinade.finance/ts-common';
/**

@@ -8,2 +8,2 @@ * Parsing provided argument a ledger url.

*/
export declare function parseLedgerWallet(pathOrUrl: string, logger: Logger): Promise<Wallet | null>;
export declare function parseLedgerWallet(pathOrUrl: string, logger?: LoggerPlaceholder): Promise<Wallet | null>;

@@ -6,2 +6,3 @@ "use strict";

const ledger_1 = require("./ledger");
const ts_common_1 = require("@marinade.finance/ts-common");
/**

@@ -18,3 +19,3 @@ * Parsing provided argument a ledger url.

const solanaLedger = await ledger_1.LedgerWallet.instance(pathOrUrl);
logger.debug('Successfully connected to Ledger device of key %s', solanaLedger.publicKey.toBase58());
(0, ts_common_1.logDebug)(logger, 'Successfully connected to Ledger device of key %s', solanaLedger.publicKey.toBase58());
return solanaLedger;

@@ -25,7 +26,7 @@ }

if (e.statusCode === 0x6d02) {
logger.error('Ledger device Solana application is not activated. ' +
(0, ts_common_1.logError)(logger, 'Ledger device Solana application is not activated. ' +
'Please, enter the Solana app on your ledger device first.');
}
else if (e.statusCode === 0x6808) {
logger.error('Solana application does not permit blind signatures. ' +
(0, ts_common_1.logError)(logger, 'Solana application does not permit blind signatures. ' +
'Please, permit it in the Solana app settings at the ledger device first.');

@@ -36,14 +37,14 @@ }

e.message.includes('Invalid channel')) {
logger.error('Ledger device seems not being acknowledged to open the ledger manager. ' +
(0, ts_common_1.logError)(logger, 'Ledger device seems not being acknowledged to open the ledger manager. ' +
'Please, open ledger manager first on your device.');
}
else if (e instanceof errors_1.LockedDeviceError) {
logger.error('Ledger device is locked. ' + 'Please, unlock it first.');
(0, ts_common_1.logError)(logger, 'Ledger device is locked. ' + 'Please, unlock it first.');
}
else if (e instanceof Error &&
e.message.includes('read from a closed HID')) {
logger.error('Ledger cannot be open, it seems to be closed. Ensure no other program uses it.');
(0, ts_common_1.logError)(logger, 'Ledger cannot be open, it seems to be closed. Ensure no other program uses it.');
}
else {
logger.error(`Failed to connect to Ledger device of key ${pathOrUrl}`);
(0, ts_common_1.logError)(logger, `Failed to connect to Ledger device of key ${pathOrUrl}`);
}

@@ -50,0 +51,0 @@ throw e;

import Solana from '@ledgerhq/hw-app-solana';
import { PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
import { LoggerPlaceholder } from '@marinade.finance/ts-common';
export declare const CLI_LEDGER_URL_PREFIX = "usb://ledger";

@@ -26,3 +27,3 @@ export declare const SOLANA_LEDGER_BIP44_BASE_PATH = "44'/501'/";

*/
static instance(ledgerUrl?: string): Promise<LedgerWallet>;
static instance(ledgerUrl?: string, logger?: LoggerPlaceholder | undefined): Promise<LedgerWallet>;
private constructor();

@@ -29,0 +30,0 @@ signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;

@@ -34,2 +34,3 @@ "use strict";

const utils_1 = require("./utils");
const ts_common_1 = require("@marinade.finance/ts-common");
exports.CLI_LEDGER_URL_PREFIX = 'usb://ledger';

@@ -45,6 +46,6 @@ exports.SOLANA_LEDGER_BIP44_BASE_PATH = "44'/501'/";

*/
static async instance(ledgerUrl = '0') {
static async instance(ledgerUrl = '0', logger = undefined) {
const { pubkey, derivedPath: parsedDerivedPath } = parseLedgerUrl(ledgerUrl);
// getting
const { api, derivedPath } = await LedgerWallet.getSolanaApi(pubkey, parsedDerivedPath, 12, 5);
const { api, derivedPath } = await LedgerWallet.getSolanaApi(pubkey, parsedDerivedPath, logger);
const publicKey = await LedgerWallet.getPublicKey(api, derivedPath);

@@ -86,3 +87,3 @@ return new LedgerWallet(api, derivedPath, publicKey);

*/
static async getSolanaApi(pubkey, derivedPath, heuristicDepth = 15, heuristicWide = 2) {
static async getSolanaApi(pubkey, derivedPath, logger = undefined, heuristicDepth = 10, heuristicWide = 3) {
const ledgerDevices = (0, hw_transport_node_hid_noevents_1.getDevices)();

@@ -112,4 +113,13 @@ if (ledgerDevices.length === 0) {

if (transport === undefined) {
console.log(`Ledger device does not provide pubkey ${pubkey.toBase58()} ` +
`at defined derivation path ${derivedPath}. A heuristic search processing.`);
(0, ts_common_1.logInfo)(logger, `Ledger device does not provide pubkey ${pubkey.toBase58()} ` +
`at defined derivation path ${derivedPath}, searching...`);
// parsing the derived path to check heuristic depth and wide
// when the derived path is 44'/501'/0/0/5
// then the wide will be 3, depth will be max of numbers as it's 5
let splitDerivedPath = derivedPath.split('/');
if (splitDerivedPath.length > 2) {
splitDerivedPath = splitDerivedPath.slice(2);
heuristicWide = splitDerivedPath.length;
heuristicDepth = Math.max(...splitDerivedPath.map(v => parseFloat(v)));
}
const heuristicsCombinations = (0, utils_1.generateAllCombinations)(heuristicDepth, heuristicWide);

@@ -120,3 +130,3 @@ for (const openedTransport of openedTransports) {

const heuristicDerivedPath = exports.SOLANA_LEDGER_BIP44_BASE_PATH + combination.join('/');
console.log('heuristicDerivedPath loop:', heuristicDerivedPath);
(0, ts_common_1.logDebug)(logger, 'search loop:', heuristicDerivedPath);
const ledgerPubkey = await LedgerWallet.getPublicKey(solanaApi, heuristicDerivedPath);

@@ -126,3 +136,3 @@ if (ledgerPubkey.equals(pubkey)) {

derivedPath = heuristicDerivedPath;
console.log(`Using derived path ${derivedPath}, pubkey ${pubkey.toBase58()}`);
(0, ts_common_1.logInfo)(logger, `Using derived path ${derivedPath}, pubkey ${pubkey.toBase58()}`);
break; // the last found transport is the one we need

@@ -129,0 +139,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc