Skip to content

Commit

Permalink
feat: ledger thorchain support (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre committed Oct 19, 2023
1 parent 6805444 commit e8a7539
Show file tree
Hide file tree
Showing 39 changed files with 888 additions and 174 deletions.
32 changes: 16 additions & 16 deletions examples/sandbox/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-sandbox",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"private": true,
"browserslist": "> 0.5%, last 2 versions, not dead",
Expand All @@ -10,21 +10,21 @@
"clean": "rm -rf dist node_modules public .parcel-cache"
},
"dependencies": {
"@shapeshiftoss/hdwallet-core": "1.52.6",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.52.6",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.52.6",
"@shapeshiftoss/hdwallet-keplr": "1.52.6",
"@shapeshiftoss/hdwallet-ledger": "1.52.6",
"@shapeshiftoss/hdwallet-ledger-webhid": "1.52.6",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.52.6",
"@shapeshiftoss/hdwallet-metamask": "1.52.6",
"@shapeshiftoss/hdwallet-native": "1.52.6",
"@shapeshiftoss/hdwallet-portis": "1.52.6",
"@shapeshiftoss/hdwallet-tallyho": "1.52.6",
"@shapeshiftoss/hdwallet-trezor": "1.52.6",
"@shapeshiftoss/hdwallet-trezor-connect": "1.52.6",
"@shapeshiftoss/hdwallet-walletconnect": "1.52.6",
"@shapeshiftoss/hdwallet-xdefi": "1.52.6",
"@shapeshiftoss/hdwallet-core": "1.52.7",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.52.7",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.52.7",
"@shapeshiftoss/hdwallet-keplr": "1.52.7",
"@shapeshiftoss/hdwallet-ledger": "1.52.7",
"@shapeshiftoss/hdwallet-ledger-webhid": "1.52.7",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.52.7",
"@shapeshiftoss/hdwallet-metamask": "1.52.7",
"@shapeshiftoss/hdwallet-native": "1.52.7",
"@shapeshiftoss/hdwallet-portis": "1.52.7",
"@shapeshiftoss/hdwallet-tallyho": "1.52.7",
"@shapeshiftoss/hdwallet-trezor": "1.52.7",
"@shapeshiftoss/hdwallet-trezor-connect": "1.52.7",
"@shapeshiftoss/hdwallet-walletconnect": "1.52.7",
"@shapeshiftoss/hdwallet-xdefi": "1.52.7",
"bip32": "^2.0.4",
"jquery": "^3.4.1",
"json": "^9.0.6",
Expand Down
20 changes: 10 additions & 10 deletions integration/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/integration",
"version": "1.52.6",
"version": "1.52.7",
"main": "index.js",
"license": "MIT",
"private": true,
Expand All @@ -10,15 +10,15 @@
"dev": "lerna run test --scope integration --parallel --include-filtered-dependencies"
},
"dependencies": {
"@shapeshiftoss/hdwallet-core": "1.52.6",
"@shapeshiftoss/hdwallet-keepkey": "1.52.6",
"@shapeshiftoss/hdwallet-keepkey-nodewebusb": "1.52.6",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.52.6",
"@shapeshiftoss/hdwallet-ledger": "1.52.6",
"@shapeshiftoss/hdwallet-native": "1.52.6",
"@shapeshiftoss/hdwallet-portis": "1.52.6",
"@shapeshiftoss/hdwallet-trezor": "1.52.6",
"@shapeshiftoss/hdwallet-xdefi": "1.52.6",
"@shapeshiftoss/hdwallet-core": "1.52.7",
"@shapeshiftoss/hdwallet-keepkey": "1.52.7",
"@shapeshiftoss/hdwallet-keepkey-nodewebusb": "1.52.7",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.52.7",
"@shapeshiftoss/hdwallet-ledger": "1.52.7",
"@shapeshiftoss/hdwallet-native": "1.52.7",
"@shapeshiftoss/hdwallet-portis": "1.52.7",
"@shapeshiftoss/hdwallet-trezor": "1.52.7",
"@shapeshiftoss/hdwallet-xdefi": "1.52.7",
"fast-json-stable-stringify": "^2.1.0",
"msw": "^0.27.1",
"whatwg-fetch": "^3.6.2"
Expand Down
3 changes: 2 additions & 1 deletion integration/src/thorchain/thorchain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import * as keepkey from "@shapeshiftoss/hdwallet-keepkey";
import * as ledger from "@shapeshiftoss/hdwallet-ledger";

import tx_unsigned_swap_amino from "./tx01.mainnet.thorchain.swap.amino.json";
import tx_unsigned_swap from "./tx01.mainnet.thorchain.swap.json";
Expand All @@ -25,7 +26,7 @@ export function thorchainTests(get: () => { wallet: core.HDWallet; info: core.HD
beforeAll(async () => {
const { wallet: w } = get();
if (core.supportsThorchain(w)) wallet = w;
useAmino = w instanceof keepkey.KeepKeyHDWallet;
useAmino = w instanceof keepkey.KeepKeyHDWallet || w instanceof ledger.LedgerHDWallet;
});

beforeEach(async () => {
Expand Down
56 changes: 56 additions & 0 deletions integration/src/wallets/ledger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import * as ledger from "@shapeshiftoss/hdwallet-ledger";
import { toByteArray } from "base64-js";

export class MockTransport extends ledger.LedgerTransport {
memoized = new Map();
Expand Down Expand Up @@ -212,6 +213,61 @@ export class MockTransport extends ledger.LedgerTransport {
'{"success":true,"coin":"Btc","method":"getWalletPublicKey","payload":{"bitcoinAddress":"1FH6ehAd5ZFXCM1cLGzHxK1s4dGdq1JusM","chainCode":"fixme","publicKey":"fixme"}}'
)
);

// Thorchain
const compress_pk = toByteArray("AxUZcTuLQr3DZxEtMxMs8Uzt+SisV3HURLpFm5SXEXuj");
this.memoize(
"Rune",
"getAddressAndPubKey",
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}]}}`
)
);

const sig1 = toByteArray(
"1s+0FVJ5R8O+ewGq5yNbTQuVG5MJZppFDqVJ4cd5D68ogOb2GMVHvYCH2dvQXo/uK/fT6Rk6dLGhK8tgW/HqtA=="
);
const r1 = sig1.slice(0, 32);
const s1 = sig1.slice(32, 64);
const rawSig1 = Uint8Array.from([48, 68, 2, 32, ...r1, 2, 32, ...s1]);
this.memoize(
"Rune",
"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"}]'
),
{
success: true,
coin: "Rune",
method: "sign",
payload: {
signature: rawSig1,
},
}
);

const sig2 = toByteArray(
"0Bjk7npdUw/Qa4MQTS4PH8sw8jM4JSzpd7G2DsF3DMVoYgdpO2fjHh/DUq6v30nghxUSJj0jNm0VIq9viPB+tQ=="
);
const r2 = sig2.slice(0, 32);
const s2 = sig2.slice(32, 64);
const rawSig2 = Uint8Array.from([48, 68, 2, 32, ...r2, 2, 32, ...s2]);
this.memoize(
"Rune",
"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"}]'
),
{
success: true,
coin: "Rune",
method: "sign",
payload: {
signature: rawSig2,
},
}
);
} catch (e) {
console.error(e);
}
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "5.2.0",
"version": "1.52.6",
"version": "1.52.7",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-coinbase/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-coinbase",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -15,7 +15,7 @@
},
"dependencies": {
"@coinbase/wallet-sdk": "^3.6.6",
"@shapeshiftoss/hdwallet-core": "1.52.6",
"@shapeshiftoss/hdwallet-core": "1.52.7",
"eth-rpc-errors": "^4.0.3",
"lodash": "^4.17.21"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/hdwallet-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-core",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand Down
6 changes: 3 additions & 3 deletions packages/hdwallet-keepkey-chromeusb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-keepkey-chromeusb",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -14,7 +14,7 @@
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@shapeshiftoss/hdwallet-core": "1.52.6",
"@shapeshiftoss/hdwallet-keepkey": "1.52.6"
"@shapeshiftoss/hdwallet-core": "1.52.7",
"@shapeshiftoss/hdwallet-keepkey": "1.52.7"
}
}
4 changes: 2 additions & 2 deletions packages/hdwallet-keepkey-electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-keepkey-electron",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -14,7 +14,7 @@
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@shapeshiftoss/hdwallet-keepkey": "1.52.6",
"@shapeshiftoss/hdwallet-keepkey": "1.52.7",
"uuid": "^8.3.2"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-keepkey-nodehid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-keepkey-nodehid",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -14,7 +14,7 @@
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@shapeshiftoss/hdwallet-keepkey": "1.52.6"
"@shapeshiftoss/hdwallet-keepkey": "1.52.7"
},
"peerDependencies": {
"node-hid": "^2.1.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/hdwallet-keepkey-nodewebusb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-keepkey-nodewebusb",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -14,8 +14,8 @@
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@shapeshiftoss/hdwallet-core": "1.52.6",
"@shapeshiftoss/hdwallet-keepkey": "1.52.6"
"@shapeshiftoss/hdwallet-core": "1.52.7",
"@shapeshiftoss/hdwallet-keepkey": "1.52.7"
},
"peerDependencies": {
"usb": "^2.3.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/hdwallet-keepkey-tcp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-keepkey-tcp",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -14,8 +14,8 @@
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@shapeshiftoss/hdwallet-core": "1.52.6",
"@shapeshiftoss/hdwallet-keepkey": "1.52.6",
"@shapeshiftoss/hdwallet-core": "1.52.7",
"@shapeshiftoss/hdwallet-keepkey": "1.52.7",
"axios": "^0.21.1"
}
}
6 changes: 3 additions & 3 deletions packages/hdwallet-keepkey-webusb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-keepkey-webusb",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -14,8 +14,8 @@
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@shapeshiftoss/hdwallet-core": "1.52.6",
"@shapeshiftoss/hdwallet-keepkey": "1.52.6"
"@shapeshiftoss/hdwallet-core": "1.52.7",
"@shapeshiftoss/hdwallet-keepkey": "1.52.7"
},
"devDependencies": {
"@types/w3c-web-usb": "^1.0.4"
Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-keepkey/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-keepkey",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -19,7 +19,7 @@
"@ethereumjs/tx": "^3.3.0",
"@keepkey/device-protocol": "^7.12.2",
"@shapeshiftoss/bitcoinjs-lib": "5.2.0-shapeshift.2",
"@shapeshiftoss/hdwallet-core": "1.52.6",
"@shapeshiftoss/hdwallet-core": "1.52.7",
"@shapeshiftoss/proto-tx-builder": "^0.8.0",
"bignumber.js": "^9.0.1",
"bnb-javascript-sdk-nobroadcast": "^2.16.14",
Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-keplr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-keplr",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -15,7 +15,7 @@
},
"dependencies": {
"@shapeshiftoss/caip": "8.15.0",
"@shapeshiftoss/hdwallet-core": "1.52.6",
"@shapeshiftoss/hdwallet-core": "1.52.7",
"@shapeshiftoss/proto-tx-builder": "^0.8.0",
"@shapeshiftoss/types": "3.1.3",
"base64-js": "^1.5.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/hdwallet-ledger-webhid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-ledger-webhid",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -19,8 +19,8 @@
"@ledgerhq/hw-transport": "^6.7.0",
"@ledgerhq/hw-transport-webhid": "^6.7.0",
"@ledgerhq/live-common": "^21.8.2",
"@shapeshiftoss/hdwallet-core": "1.52.6",
"@shapeshiftoss/hdwallet-ledger": "1.52.6",
"@shapeshiftoss/hdwallet-core": "1.52.7",
"@shapeshiftoss/hdwallet-ledger": "1.52.7",
"@types/w3c-web-hid": "^1.0.2"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/hdwallet-ledger-webusb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shapeshiftoss/hdwallet-ledger-webusb",
"version": "1.52.6",
"version": "1.52.7",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -20,8 +20,8 @@
"@ledgerhq/hw-transport-webusb": "^6.7.0",
"@ledgerhq/live-common": "^21.8.2",
"@ledgerhq/logs": "^6.10.1",
"@shapeshiftoss/hdwallet-core": "1.52.6",
"@shapeshiftoss/hdwallet-ledger": "1.52.6",
"@shapeshiftoss/hdwallet-core": "1.52.7",
"@shapeshiftoss/hdwallet-ledger": "1.52.7",
"@types/w3c-web-usb": "^1.0.4",
"p-queue": "^7.4.1"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/hdwallet-ledger-webusb/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ 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 Down
Loading

1 comment on commit e8a7539

@vercel
Copy link

@vercel vercel bot commented on e8a7539 Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

hdwallet – ./

hdwallet-git-master-shapeshift.vercel.app
hdwallet-shapeshift.vercel.app

Please sign in to comment.