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

feat: add cosmos to ledger #659

Merged
merged 3 commits into from
Jan 22, 2024
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
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.14",
"version": "1.53.0",
"license": "MIT",
"private": true,
"browserslist": "> 0.5%, last 2 versions, not dead",
Expand All @@ -11,21 +11,21 @@
},
"dependencies": {
"@metamask/eth-sig-util": "^7.0.0",
"@shapeshiftoss/hdwallet-core": "1.52.14",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.52.14",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.52.14",
"@shapeshiftoss/hdwallet-keplr": "1.52.14",
"@shapeshiftoss/hdwallet-ledger": "1.52.14",
"@shapeshiftoss/hdwallet-ledger-webhid": "1.52.14",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.52.14",
"@shapeshiftoss/hdwallet-metamask": "1.52.14",
"@shapeshiftoss/hdwallet-native": "1.52.14",
"@shapeshiftoss/hdwallet-portis": "1.52.14",
"@shapeshiftoss/hdwallet-tallyho": "1.52.14",
"@shapeshiftoss/hdwallet-trezor": "1.52.14",
"@shapeshiftoss/hdwallet-trezor-connect": "1.52.14",
"@shapeshiftoss/hdwallet-walletconnect": "1.52.14",
"@shapeshiftoss/hdwallet-xdefi": "1.52.14",
"@shapeshiftoss/hdwallet-core": "1.53.0",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.53.0",
"@shapeshiftoss/hdwallet-keepkey-webusb": "1.53.0",
"@shapeshiftoss/hdwallet-keplr": "1.53.0",
"@shapeshiftoss/hdwallet-ledger": "1.53.0",
"@shapeshiftoss/hdwallet-ledger-webhid": "1.53.0",
"@shapeshiftoss/hdwallet-ledger-webusb": "1.53.0",
"@shapeshiftoss/hdwallet-metamask": "1.53.0",
"@shapeshiftoss/hdwallet-native": "1.53.0",
"@shapeshiftoss/hdwallet-portis": "1.53.0",
"@shapeshiftoss/hdwallet-tallyho": "1.53.0",
"@shapeshiftoss/hdwallet-trezor": "1.53.0",
"@shapeshiftoss/hdwallet-trezor-connect": "1.53.0",
"@shapeshiftoss/hdwallet-walletconnect": "1.53.0",
"@shapeshiftoss/hdwallet-xdefi": "1.53.0",
"bip32": "^2.0.4",
"eip-712": "^1.0.0",
"jquery": "^3.7.1",
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.14",
"version": "1.53.0",
"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.14",
"@shapeshiftoss/hdwallet-keepkey": "1.52.14",
"@shapeshiftoss/hdwallet-keepkey-nodewebusb": "1.52.14",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.52.14",
"@shapeshiftoss/hdwallet-ledger": "1.52.14",
"@shapeshiftoss/hdwallet-native": "1.52.14",
"@shapeshiftoss/hdwallet-portis": "1.52.14",
"@shapeshiftoss/hdwallet-trezor": "1.52.14",
"@shapeshiftoss/hdwallet-xdefi": "1.52.14",
"@shapeshiftoss/hdwallet-core": "1.53.0",
"@shapeshiftoss/hdwallet-keepkey": "1.53.0",
"@shapeshiftoss/hdwallet-keepkey-nodewebusb": "1.53.0",
"@shapeshiftoss/hdwallet-keepkey-tcp": "1.53.0",
"@shapeshiftoss/hdwallet-ledger": "1.53.0",
"@shapeshiftoss/hdwallet-native": "1.53.0",
"@shapeshiftoss/hdwallet-portis": "1.53.0",
"@shapeshiftoss/hdwallet-trezor": "1.53.0",
"@shapeshiftoss/hdwallet-xdefi": "1.53.0",
"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/cosmos/cosmos.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";

// Amino-encoded transactions
import tx_unsigned_delegate_cosmos_amino from "./amino/tx01.mainnet.cosmos.delegate.json";
Expand Down Expand Up @@ -43,7 +44,7 @@ export function cosmosTests(get: () => { wallet: core.HDWallet; info: core.HDWal
beforeAll(async () => {
const { wallet: w } = get();
if (core.supportsCosmos(w)) wallet = w;
useAmino = w instanceof keepkey.KeepKeyHDWallet;
useAmino = w instanceof keepkey.KeepKeyHDWallet || w instanceof ledger.LedgerHDWallet;
});

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

const getRawSig = (sig: string) => {
const sigBz = toByteArray(sig);
const r = sigBz.slice(0, 32);
const s = sigBz.slice(32, 64);
return Uint8Array.from([48, 68, 2, 32, ...r, 2, 32, ...s]);
};

export class MockTransport extends ledger.LedgerTransport {
memoized = new Map();
currentApp: string;
Expand Down Expand Up @@ -225,12 +232,6 @@ export class MockTransport extends ledger.LedgerTransport {
)
);

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",
Expand All @@ -242,17 +243,13 @@ export class MockTransport extends ledger.LedgerTransport {
coin: "Rune",
method: "sign",
payload: {
signature: rawSig1,
signature: getRawSig(
"1s+0FVJ5R8O+ewGq5yNbTQuVG5MJZppFDqVJ4cd5D68ogOb2GMVHvYCH2dvQXo/uK/fT6Rk6dLGhK8tgW/HqtA=="
),
},
}
);

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",
Expand All @@ -264,7 +261,127 @@ export class MockTransport extends ledger.LedgerTransport {
coin: "Rune",
method: "sign",
payload: {
signature: rawSig2,
signature: getRawSig(
"0Bjk7npdUw/Qa4MQTS4PH8sw8jM4JSzpd7G2DsF3DMVoYgdpO2fjHh/DUq6v30nghxUSJj0jNm0VIq9viPB+tQ=="
),
},
}
);

// Cosmos
this.memoize(
"Cosmos",
"getAddress",
JSON.parse(`["m/44'/118'/0'/0/0", "cosmos"]`),
JSON.parse(
'{"success":true,"coin":"Cosmos","method":"getAddress","payload":{"address":"cosmos15cenya0tr7nm3tz2wn3h3zwkht2rxrq7q7h3dj","publicKey":"03bee3af30e53a73f38abc5a2fcdac426d7b04eb72a8ebd3b01992e2d206e24ad8"}}'
)
);

this.memoize(
"Cosmos",
"sign",
JSON.parse(
`["m/44'/118'/0'/0/0","{\\"account_number\\":\\"16359\\",\\"chain_id\\":\\"cosmoshub-4\\",\\"fee\\":{\\"amount\\":[{\\"amount\\":\\"900\\",\\"denom\\":\\"uatom\\"}],\\"gas\\":\\"90000\\"},\\"memo\\":\\"\\",\\"msgs\\":[{\\"type\\":\\"cosmos-sdk/MsgSend\\",\\"value\\":{\\"amount\\":[{\\"amount\\":\\"9000\\",\\"denom\\":\\"uatom\\"}],\\"from_address\\":\\"cosmos15cenya0tr7nm3tz2wn3h3zwkht2rxrq7q7h3dj\\",\\"to_address\\":\\"cosmos19xq52fdl5x2pp8gu4ph0ytzjz8msrdxwtjlm95\\"}}],\\"sequence\\":\\"29\\"}"]`
),
{
success: true,
coin: "Cosmos",
method: "sign",
payload: {
signature: getRawSig(
"5R1jQIAu45Ded6nIuzusHIKOuR2sAsFFGvMbCumCbhE3k86gYOKUlJ3829dwe6n2clMueEbLeESMBG/dhAMeDA=="
),
},
}
);

this.memoize(
"Cosmos",
"sign",
JSON.parse(
`["m/44'/118'/0'/0/0","{\\"account_number\\":\\"16359\\",\\"chain_id\\":\\"cosmoshub-4\\",\\"fee\\":{\\"amount\\":[{\\"amount\\":\\"2500\\",\\"denom\\":\\"uatom\\"}],\\"gas\\":\\"250000\\"},\\"memo\\":\\"\\",\\"msgs\\":[{\\"type\\":\\"cosmos-sdk/MsgDelegate\\",\\"value\\":{\\"amount\\":{\\"amount\\":\\"10000\\",\\"denom\\":\\"uatom\\"},\\"delegator_address\\":\\"cosmos15cenya0tr7nm3tz2wn3h3zwkht2rxrq7q7h3dj\\",\\"validator_address\\":\\"cosmosvaloper199mlc7fr6ll5t54w7tts7f4s0cvnqgc59nmuxf\\"}}],\\"sequence\\":\\"35\\"}"]`
),
{
success: true,
coin: "Cosmos",
method: "sign",
payload: {
signature: getRawSig(
"lM+NkHlL5lx1Kt8/3TQXZo3TENWb+qWBsJ5XQFq7WekHw4O+YF6Iv0aCqoH7YD40vYubGZpZXcjMZy/mAbe0cA=="
),
},
}
);

this.memoize(
"Cosmos",
"sign",
JSON.parse(
`["m/44'/118'/0'/0/0","{\\"account_number\\":\\"16359\\",\\"chain_id\\":\\"cosmoshub-4\\",\\"fee\\":{\\"amount\\":[{\\"amount\\":\\"2500\\",\\"denom\\":\\"uatom\\"}],\\"gas\\":\\"250000\\"},\\"msgs\\":[{\\"type\\":\\"cosmos-sdk/MsgUndelegate\\",\\"value\\":{\\"amount\\":{\\"amount\\":\\"10000\\",\\"denom\\":\\"uatom\\"},\\"delegator_address\\":\\"cosmos15cenya0tr7nm3tz2wn3h3zwkht2rxrq7q7h3dj\\",\\"validator_address\\":\\"cosmosvaloper199mlc7fr6ll5t54w7tts7f4s0cvnqgc59nmuxf\\"}}],\\"sequence\\":\\"37\\"}"]`
),
{
success: true,
coin: "Cosmos",
method: "sign",
payload: {
signature: getRawSig(
"mfJjZ2w5iNDFJ1bTsw/Ln3LPbOZ0r33jqrIz0LB3LNYFNq7X+uFV/UErZiehSDAwv09PgF24+zi8Ip7yZ1ISkQ=="
),
},
}
);

this.memoize(
"Cosmos",
"sign",
JSON.parse(
`["m/44'/118'/0'/0/0","{\\"account_number\\":\\"16359\\",\\"chain_id\\":\\"cosmoshub-4\\",\\"fee\\":{\\"amount\\":[{\\"amount\\":\\"2500\\",\\"denom\\":\\"uatom\\"}],\\"gas\\":\\"250000\\"},\\"memo\\":\\"\\",\\"msgs\\":[{\\"type\\":\\"cosmos-sdk/MsgBeginRedelegate\\",\\"value\\":{\\"amount\\":{\\"amount\\":\\"1000\\",\\"denom\\":\\"uatom\\"},\\"delegator_address\\":\\"cosmos15cenya0tr7nm3tz2wn3h3zwkht2rxrq7q7h3dj\\",\\"validator_dst_address\\":\\"cosmosvaloper199mlc7fr6ll5t54w7tts7f4s0cvnqgc59nmuxf\\",\\"validator_src_address\\":\\"cosmosvaloper1qwl879nx9t6kef4supyazayf7vjhennyh568ys\\"}}],\\"sequence\\":\\"33\\"}"]`
),
{
success: true,
coin: "Cosmos",
method: "sign",
payload: {
signature: getRawSig(
"kskHVIe2AyWzRpHszO/9ePI4yVgcAWB10lWbolEOBCpDSIeD0JWTX4x1TO3lnKNMawcm2NfGyTh3GseC7s+BRg=="
),
},
}
);

this.memoize(
"Cosmos",
"sign",
JSON.parse(
`["m/44'/118'/0'/0/0","{\\"account_number\\":\\"16359\\",\\"chain_id\\":\\"cosmoshub-4\\",\\"fee\\":{\\"amount\\":[{\\"amount\\":\\"1400\\",\\"denom\\":\\"uatom\\"}],\\"gas\\":\\"140000\\"},\\"memo\\":\\"\\",\\"msgs\\":[{\\"type\\":\\"cosmos-sdk/MsgWithdrawDelegationReward\\",\\"value\\":{\\"delegator_address\\":\\"cosmos15cenya0tr7nm3tz2wn3h3zwkht2rxrq7q7h3dj\\",\\"validator_address\\":\\"cosmosvaloper1qwl879nx9t6kef4supyazayf7vjhennyh568ys\\"}}],\\"sequence\\":\\"31\\"}"]`
),
{
success: true,
coin: "Cosmos",
method: "sign",
payload: {
signature: getRawSig(
"rxrww6IUxj89HZ3Yx3dH51/SkRZzHzuSwH4ZwCGUSc4ggVuiaPCyClO1q8CGQDuc/D9Lx6JWDnnaQnvty8RkCw=="
),
},
}
);

this.memoize(
"Cosmos",
"sign",
JSON.parse(
`["m/44'/118'/0'/0/0","{\\"account_number\\":\\"16359\\",\\"chain_id\\":\\"cosmoshub-4\\",\\"fee\\":{\\"amount\\":[{\\"amount\\":\\"4500\\",\\"denom\\":\\"uatom\\"}],\\"gas\\":\\"450000\\"},\\"memo\\":\\"\\",\\"msgs\\":[{\\"type\\":\\"cosmos-sdk/MsgTransfer\\",\\"value\\":{\\"receiver\\":\\"osmo15cenya0tr7nm3tz2wn3h3zwkht2rxrq7g9ypmq\\",\\"sender\\":\\"cosmos15cenya0tr7nm3tz2wn3h3zwkht2rxrq7q7h3dj\\",\\"source_channel\\":\\"channel-141\\",\\"source_port\\":\\"transfer\\",\\"timeout_height\\":{\\"revision_height\\":\\"4006321\\",\\"revision_number\\":\\"1\\"},\\"token\\":{\\"amount\\":\\"5500\\",\\"denom\\":\\"uatom\\"}}}],\\"sequence\\":\\"39\\"}"]`
),
{
success: true,
coin: "Cosmos",
method: "sign",
payload: {
signature: getRawSig(
"cZPi9Dkq4b0NoePZWwN6QIxgu4Yi0i64iKgsDx3eAftX3j/jtQCxE75oxw583j2tm4xwj8r5t/3CU0WqAAEGbw=="
),
},
}
);
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.14",
"version": "1.53.0",
"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.14",
"version": "1.53.0",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -15,7 +15,7 @@
},
"dependencies": {
"@coinbase/wallet-sdk": "^3.6.6",
"@shapeshiftoss/hdwallet-core": "1.52.14",
"@shapeshiftoss/hdwallet-core": "1.53.0",
"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.14",
"version": "1.53.0",
"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.14",
"version": "1.53.0",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -14,7 +14,7 @@
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@shapeshiftoss/hdwallet-core": "1.52.14",
"@shapeshiftoss/hdwallet-keepkey": "1.52.14"
"@shapeshiftoss/hdwallet-core": "1.53.0",
"@shapeshiftoss/hdwallet-keepkey": "1.53.0"
}
}
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.14",
"version": "1.53.0",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -14,7 +14,7 @@
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@shapeshiftoss/hdwallet-keepkey": "1.52.14",
"@shapeshiftoss/hdwallet-keepkey": "1.53.0",
"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.14",
"version": "1.53.0",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -14,7 +14,7 @@
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@shapeshiftoss/hdwallet-keepkey": "1.52.14"
"@shapeshiftoss/hdwallet-keepkey": "1.53.0"
},
"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.14",
"version": "1.53.0",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -14,8 +14,8 @@
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@shapeshiftoss/hdwallet-core": "1.52.14",
"@shapeshiftoss/hdwallet-keepkey": "1.52.14"
"@shapeshiftoss/hdwallet-core": "1.53.0",
"@shapeshiftoss/hdwallet-keepkey": "1.53.0"
},
"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.14",
"version": "1.53.0",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -14,8 +14,8 @@
"prepublishOnly": "yarn clean && yarn build"
},
"dependencies": {
"@shapeshiftoss/hdwallet-core": "1.52.14",
"@shapeshiftoss/hdwallet-keepkey": "1.52.14",
"@shapeshiftoss/hdwallet-core": "1.53.0",
"@shapeshiftoss/hdwallet-keepkey": "1.53.0",
"axios": "^0.21.1"
}
}
Loading
Loading