Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Faust committed May 15, 2020
1 parent 0c4d27e commit aa601d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/platform-sdk-lsk/src/services/ledger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contracts, Exceptions } from "@arkecosystem/platform-sdk";
import { Contracts, Exceptions, Utils } from "@arkecosystem/platform-sdk";
import LedgerTransport from "@ledgerhq/hw-transport-node-hid-singleton";
import { DposLedger, LedgerAccount, SupportedCoin } from "dpos-ledger-api";
import Lisk from "lisk-elements";
Expand All @@ -9,6 +9,7 @@ export class LedgerService implements Contracts.LedgerService {

private constructor(transport: Contracts.LedgerTransport) {
this.#ledger = transport;
// @ts-ignore
this.#transport = new DposLedger(transport);
}

Expand All @@ -33,8 +34,8 @@ export class LedgerService implements Contracts.LedgerService {
public async signTransaction(path: string, payload: Buffer): Promise<string> {
const signature: Buffer = await this.#transport.signTX(
this.getLedgerAccount(path),
Lisk.transaction.utils.getTransactionBytes(payload),
false,
// @ts-ignore
Lisk.transaction.utils.getTransactionBytes(payload)
);

return signature.toString("hex");
Expand All @@ -57,7 +58,7 @@ export class LedgerService implements Contracts.LedgerService {
private getLedgerAccount(path: string): LedgerAccount {
const account: LedgerAccount = new LedgerAccount();
account.coinIndex(SupportedCoin.LISK);
account.account(path); // todo: parse account index from path
account.account(Utils.BIP44.parse(path).account);

return account;
}
Expand Down
19 changes: 19 additions & 0 deletions packages/platform-sdk/src/utils/bip44.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,23 @@ export class BIP44 {

return bip32.fromSeed(bip39.mnemonicToSeedSync(passphrase));
}

public static parse(path: string) {
if (!path.match(new RegExp("^((m/)?(44'?)){1}(/[0-9]+'?){2}(/[0-9]+){2}$", "g"))) {
throw new Error(path);
}

const result: number[] = [];
for (const level of path.replace("m/", "").split("/")) {
result.push(+level.replace("'", ""));
}

return {
purpose: result[0],
coinType: result[1],
account: result[2],
change: result[3],
addressIndex: result[4],
};
}
}

0 comments on commit aa601d6

Please sign in to comment.