Skip to content

Commit

Permalink
fix: remove troubleshooting, signing and get_public_key works
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheng-Long committed Jan 22, 2025
1 parent 83db304 commit 7b408a5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
9 changes: 9 additions & 0 deletions .changeset/lazy-taxis-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@ledgerhq/hw-app-hedera": minor
"@ledgerhq/types-live": minor
"@ledgerhq/coin-hedera": minor
"@ledgerhq/coin-framework": minor
"@ledgerhq/live-env": minor
---

Allows for Hedera ECDSA Keys to be used
2 changes: 1 addition & 1 deletion libs/coin-framework/src/bridge/jsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export const makeScanAccounts =
log("scanAccounts", `scanning ${currency.id} on derivationMode=${derivationMode}`);
let result: Result = derivationsCache[path];

if (!result) {
if (!result || derivationMode == "hederaBip44Ecdsa") {
try {
result = await getAddressFn(deviceId, {
currency,
Expand Down
4 changes: 2 additions & 2 deletions libs/coin-framework/src/derivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ const modes: Readonly<Record<DerivationMode, ModeSpec>> = Object.freeze({
overridesDerivation: "44'/501'/<account>'",
},
hederaBip44Ed25519: {
overridesDerivation: "44/3030",
overridesDerivation: "44/3030/0",
},
hederaBip44Ecdsa: {
overridesDerivation: "44/3030",
overridesDerivation: "44/3030/1",
},
cardano: {
purpose: 1852,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export const getAccountShape: GetAccountShape<Account> = async (
};

export const buildIterateResult: IterateResultBuilder = async ({ result: rootResult }) => {
console.log(rootResult.publicKey);
const accounts = await getAccountsForPublicKey(rootResult.publicKey);
const addresses = accounts.map(a => a.accountId.toString());

Expand Down
4 changes: 1 addition & 3 deletions libs/coin-modules/coin-hedera/src/signer/getAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
const resolver = (signerContext: SignerContext<HederaSigner>): GetAddressFn => {
return async (deviceId: string, { path, derivationMode }: GetAddressOptions) => {
let publicKey = "";
console.log(derivationMode);
publicKey = await signerContext(deviceId, signer => signer.getPublicKey(path));
if (derivationMode == "hederaBip44Ecdsa") {
publicKey = await signerContext(deviceId, signer => signer.getPublicKey(path, true));
console.log(publicKey);
}
publicKey = await signerContext(deviceId, signer => signer.getPublicKey(path));

return {
path,
Expand Down
13 changes: 5 additions & 8 deletions libs/ledgerjs/packages/hw-app-hedera/src/Hedera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,30 @@ export default class Hedera {
* @return the public key
*/
async getPublicKey(path: string, ecdsa?: boolean): Promise<string> {
console.log("path: " + path);
const bipPath = BIPPath.fromString(path).toPathArray();
const serializedPath = this._serializePath(bipPath);

//44/3030/0

const p1 = 0x01;
let p2 = 0x00;

if (ecdsa) {
p2 = 1;
}

console.log("getting key...");

const response = await this.transport.send(CLA, INS.GET_PUBLIC_KEY, p1, p2, serializedPath);

console.log(response);

const returnCodeBytes = response.slice(-2);
const returnCode = (returnCodeBytes[0] << 8) | returnCodeBytes[1];

if (returnCode === STATUS.USER_CANCEL) {
throw new UserRefusedAddress();
}

return response.slice(0, 32).toString("hex");
if (ecdsa) {
return response.slice(0, 33).toString("hex");
} else {
return response.slice(0, 32).toString("hex");
}
}

// TODO: the BOLOS app does not support anything but index #0 for signing transactions
Expand Down
2 changes: 0 additions & 2 deletions libs/ledgerjs/packages/hw-transport/src/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ export default class Transport {
}

tracer.trace("Starting an exchange", { abortTimeoutMs });
console.log("apdu: " + cla + " " + ins + " " + p1 + " " + p2 + " " + data);
console.log("p2: " + p2);
const response = await this.exchange(
// The size of the data is added in 1 byte just before `data`
Buffer.concat([Buffer.from([cla, ins, p1, p2]), Buffer.from([data.length]), data]),
Expand Down

0 comments on commit 7b408a5

Please sign in to comment.