Skip to content

Commit

Permalink
chore: ledger thorchain cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladinlight committed Jan 23, 2024
1 parent 2209e26 commit 8a142c1
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 451 deletions.
15 changes: 7 additions & 8 deletions integration/src/wallets/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,20 @@ export class MockTransport extends ledger.LedgerTransport {
);

// Thorchain
const compress_pk = toByteArray("AxUZcTuLQr3DZxEtMxMs8Uzt+SisV3HURLpFm5SXEXuj");
this.memoize(
"Rune",
"getAddressAndPubKey",
"Thorchain",
"getAddress",
JSON.parse(`[[${core.bip32ToAddressNList("m/44'/931'/0'/0/0")}], "thor"]`),
JSON.parse(
`{"success":true,"coin":"Rune","method":"getAddressAndPubkey","payload":{"bech32_address":"thor1ls33ayg26kmltw7jjy55p32ghjna09zp74t4az","compressed_pk":[${compress_pk}]}}`
`{"success":true,"coin":"Rune","method":"getAddressAndPubkey","payload":{"address":"thor1ls33ayg26kmltw7jjy55p32ghjna09zp74t4az","publicKey":"031519713b8b42bdc367112d33132cf14cedf928ac5771d444ba459b9497117ba3"}}`
)
);

this.memoize(
"Rune",
"Thorchain",
"sign",
JSON.parse(
'[{"tx":{"account_number":"17","chain_id":"thorchain-mainnet-v1","sequence":"2","fee":{"amount":[{"amount":"3000","denom":"rune"}],"gas":"200000"},"memo":"","msg":[{"type":"thorchain/MsgSend","value":{"amount":[{"amount":"100","denom":"rune"}],"from_address":"thor1ls33ayg26kmltw7jjy55p32ghjna09zp74t4az","to_address":"thor1wy58774wagy4hkljz9mchhqtgk949zdwwe80d5"}}],"signatures":[]},"addressNList":[2147483692,2147484579,2147483648,0,0],"chain_id":"thorchain-mainnet-v1","account_number":"17","sequence":"2"}]'
'[[2147483692,2147484579,2147483648,0,0],"{\\"account_number\\":\\"17\\",\\"chain_id\\":\\"thorchain-mainnet-v1\\",\\"fee\\":{\\"amount\\":[{\\"amount\\":\\"3000\\",\\"denom\\":\\"rune\\"}],\\"gas\\":\\"200000\\"},\\"memo\\":\\"\\",\\"msgs\\":[{\\"type\\":\\"thorchain/MsgSend\\",\\"value\\":{\\"amount\\":[{\\"amount\\":\\"100\\",\\"denom\\":\\"rune\\"}],\\"from_address\\":\\"thor1ls33ayg26kmltw7jjy55p32ghjna09zp74t4az\\",\\"to_address\\":\\"thor1wy58774wagy4hkljz9mchhqtgk949zdwwe80d5\\"}}],\\"sequence\\":\\"2\\"}"]'
),
{
success: true,
Expand All @@ -251,10 +250,10 @@ export class MockTransport extends ledger.LedgerTransport {
);

this.memoize(
"Rune",
"Thorchain",
"sign",
JSON.parse(
'[{"tx":{"account_number":"2722","chain_id":"thorchain-mainnet-v1","sequence":"4","fee":{"amount":[{"amount":"0","denom":"rune"}],"gas":"350000"},"memo":"","msg":[{"type":"thorchain/MsgDeposit","value":{"coins":[{"asset":"THOR.RUNE","amount":"50994000"}],"memo":"SWAP:BNB.BNB:bnb12splwpg8jenr9pjw3dwc5rr35t8792y8pc4mtf:348953501","signer":"thor1ls33ayg26kmltw7jjy55p32ghjna09zp74t4az"}}],"signatures":[]},"addressNList":[2147483692,2147484579,2147483648,0,0],"chain_id":"thorchain-mainnet-v1","account_number":"2722","sequence":"4"}]'
'[[2147483692,2147484579,2147483648,0,0],"{\\"account_number\\":\\"2722\\",\\"chain_id\\":\\"thorchain-mainnet-v1\\",\\"fee\\":{\\"amount\\":[{\\"amount\\":\\"0\\",\\"denom\\":\\"rune\\"}],\\"gas\\":\\"350000\\"},\\"memo\\":\\"\\",\\"msgs\\":[{\\"type\\":\\"thorchain/MsgDeposit\\",\\"value\\":{\\"coins\\":[{\\"amount\\":\\"50994000\\",\\"asset\\":\\"THOR.RUNE\\"}],\\"memo\\":\\"SWAP:BNB.BNB:bnb12splwpg8jenr9pjw3dwc5rr35t8792y8pc4mtf:348953501\\",\\"signer\\":\\"thor1ls33ayg26kmltw7jjy55p32ghjna09zp74t4az\\"}}],\\"sequence\\":\\"4\\"}"]'
),
{
success: true,
Expand Down
14 changes: 7 additions & 7 deletions packages/hdwallet-ledger-webusb/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import getAppAndVersion from "@ledgerhq/live-common/lib/hw/getAppAndVersion";
import getDeviceInfo from "@ledgerhq/live-common/lib/hw/getDeviceInfo";
import openApp from "@ledgerhq/live-common/lib/hw/openApp";
import * as core from "@shapeshiftoss/hdwallet-core";
import * as ledger from "@shapeshiftoss/hdwallet-ledger";
import { LedgerTransport, Thorchain } from "@shapeshiftoss/hdwallet-ledger";
import {
LedgerResponse,
LedgerTransportCoinType,
Expand Down Expand Up @@ -80,11 +80,6 @@ export async function translateCoinAndMethod<T extends LedgerTransportCoinType,
method: U
): Promise<LedgerTransportMethod<T, U>> {
switch (coin) {
case "Rune": {
const thor = new ledger.THORChainApp(transport);
const methodInstance = thor[method as LedgerTransportMethodName<"Rune">].bind(thor);
return methodInstance as LedgerTransportMethod<T, U>;
}
case "Btc": {
const btc = new Btc({ transport });
const methodInstance = btc[method as LedgerTransportMethodName<"Btc">].bind(btc);
Expand All @@ -95,6 +90,11 @@ export async function translateCoinAndMethod<T extends LedgerTransportCoinType,
const methodInstance = eth[method as LedgerTransportMethodName<"Eth">].bind(eth);
return methodInstance as LedgerTransportMethod<T, U>;
}
case "Thorchain": {
const thorchain = new Thorchain(transport);
const methodInstance = thorchain[method as LedgerTransportMethodName<"Thorchain">].bind(thorchain);
return methodInstance as LedgerTransportMethod<T, U>;
}
case "Cosmos": {
const cosmos = new Cosmos(transport);
const methodInstance = cosmos[method as LedgerTransportMethodName<"Cosmos">].bind(cosmos);
Expand Down Expand Up @@ -130,7 +130,7 @@ export async function translateCoinAndMethod<T extends LedgerTransportCoinType,
}
}

export class LedgerWebUsbTransport extends ledger.LedgerTransport {
export class LedgerWebUsbTransport extends LedgerTransport {
device: USBDevice;

constructor(device: USBDevice, transport: TransportWebUSB, keyring: core.Keyring) {
Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-ledger/src/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const cosmosSignTx = async (

const { address, publicKey } = getAddressResponse.payload;

const rawTx = stringifyKeysInOrder({
const unsignedTx = stringifyKeysInOrder({
account_number: msg.account_number,
chain_id: ATOM_CHAIN,
fee: { amount: msg.tx.fee.amount, gas: msg.tx.fee.gas },
Expand All @@ -41,7 +41,7 @@ export const cosmosSignTx = async (
sequence: msg.sequence,
});

const signResponse = await transport.call("Cosmos", "sign", bip32path, rawTx);
const signResponse = await transport.call("Cosmos", "sign", bip32path, unsignedTx);

handleError(signResponse, transport, "Unable to obtain signature from device.");

Expand Down
24 changes: 0 additions & 24 deletions packages/hdwallet-ledger/src/thorchain/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,3 @@ export function processErrorResponse(response: any) {
error_message: response.toString(),
};
}

export async function getVersion(transport: any) {
return transport.send(CLA, INS.GET_VERSION, 0, 0).then((response: any) => {
const errorCodeData = response.slice(-2);
const returnCode = errorCodeData[0] * 256 + errorCodeData[1];

let targetId = 0;
if (response.length >= 9) {
targetId = (response[5] << 24) + (response[6] << 16) + (response[7] << 8) + (response[8] << 0);
}

return {
return_code: returnCode,
error_message: errorCodeToString(returnCode),
// ///
test_mode: response[0] !== 0,
major: response[1],
minor: response[2],
patch: response[3],
device_locked: response[4] === 1,
target_id: targetId.toString(16),
};
}, processErrorResponse);
}
68 changes: 0 additions & 68 deletions packages/hdwallet-ledger/src/thorchain/helpers.ts

This file was deleted.

Loading

0 comments on commit 8a142c1

Please sign in to comment.