Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for ledger derivation paths #52

Merged
merged 2 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ reports/*
!reports/.gitkeep
payout_wallet_private.key
remote-signer.hjson
ledger-signer.hjson

# bundling
bin/*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "breadcrumbs",
"version": "0.0.5-alpha",
"version": "0.0.6-alpha",
"description": "",
"main": "index.js",
"targets": {
Expand Down
41 changes: 40 additions & 1 deletion src/tezos-client/signers/ledger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
import TransportWebHID from "@ledgerhq/hw-transport-node-hid";
import { LedgerSigner } from "@taquito/ledger-signer";
import { readFile } from "fs/promises";
import { LEDGER_SIGNER_CONFIG_FILE } from "src/utils/constants";
import { parse } from "hjson";
import { get } from "lodash";

export const loadLedgerSignerConfig = async () => {
const config = {
derivation_path: `44'/1729'/0'/0'`,
/*
ED25519 = 0,
SECP256K1 = 1,
P256 = 2
*/
derivation_type: 0,
};
try {
Object.assign(
config,
parse((await readFile(LEDGER_SIGNER_CONFIG_FILE)).toString())
);
} catch (err) {
if (get(err, "code") !== "ENOENT") {
console.log(
`Failed to load ledger configuration from ${LEDGER_SIGNER_CONFIG_FILE} - ${get(
err,
"message",
err
)}`
);
}
}
return config;
};

export const getLedgerSigner = async () => {
console.log(`Please confirm public key export on your ledger:`);
const config = await loadLedgerSignerConfig();
const transport = await TransportWebHID.create();
const ledgerSigner = new LedgerSigner(transport);
const ledgerSigner = new LedgerSigner(
transport,
config.derivation_path,
undefined,
config.derivation_type
);
await ledgerSigner.publicKey();
console.log(`Ledger connected.`);
return ledgerSigner;
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const MUTEZ_FACTOR = 1000000;
export const CONFIG_FILE = `config.hjson`;
export const WALLET_PRIVATE_KEY_FILE = `payout_wallet_private.key`;
export const REMOTE_SIGNER_CONFIG_FILE = `remote-signer.hjson`;
export const LEDGER_SIGNER_CONFIG_FILE = `ledger-signer.hjson`;
// reports
export const REPORTS_DIRECTORY = "reports";
export const REPORTS_SUCCESS_PAYMENTS_DIRECTORY = join(
Expand Down