Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
Adding helper function for ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
msteiner96 committed Feb 10, 2022
1 parent 7cfc448 commit c82a3fd
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 12 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
"@cosmjs/crypto": "0.27.1",
"@cosmjs/encoding": "0.27.1",
"@cosmjs/faucet-client": "0.27.1",
"@cosmjs/ledger-amino": "0.27.1",
"@cosmjs/proto-signing": "0.27.1",
"@cosmjs/stargate": "0.27.1"
"@cosmjs/stargate": "0.27.1",
"@ledgerhq/hw-transport-webusb": "6.24.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.11.0",
Expand All @@ -48,10 +50,10 @@
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^5.2.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"prettier": "^2.5.1",
"typescript": "^4.5.5",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-simple-import-sort": "^7.0.0"
"typescript": "^4.5.5"
}
}
38 changes: 34 additions & 4 deletions src/helpers/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
* (c) Node / Local Mnemonic
* (d) Node / Ledger
*/
import TransportWebUSB from "@ledgerhq/hw-transport-webusb";

import { SigningCosmWasmClient } from "../cosmwasm-stargate";
import { LedgerSigner } from "../ledger-amino";
import { DirectSecp256k1HdWallet } from "../proto-signing";
import { GasPrice } from "../stargate";
import { GasPrice, makeCosmoshubPath } from "../stargate";

/**
* All setup functions are using the same config pattern
Expand Down Expand Up @@ -55,6 +58,33 @@ export async function setupKeplrWeb(config: Config): Promise<SigningCosmWasmClie
return signingClient;
}

/**
* (b) Web / Ledger
* Returns a signing client after the usergave permissions.
*
* @param config
* @returns
*/
export async function setupLedgerWeb(config: Config): Promise<SigningCosmWasmClient> {
const { prefix, gasPrice } = config;
const interactiveTimeout = 120_000;
const ledgerTransport = await TransportWebUSB.create(interactiveTimeout, interactiveTimeout);

// Setup signer
const offlineSigner = new LedgerSigner(ledgerTransport, {
hdPaths: [makeCosmoshubPath(0)],
prefix: prefix,
});

// Init SigningCosmWasmClient client
const client = await SigningCosmWasmClient.connectWithSigner(config.rpcEndpoint, offlineSigner, {
prefix,
gasPrice,
});

return client;
}

/**
* (c) Node / Local Mnemonic
* Using a local mnemonic and returns a signing clien
Expand All @@ -66,11 +96,11 @@ export async function setupKeplrWeb(config: Config): Promise<SigningCosmWasmClie
export async function setupNodeLocal(config: Config, mnemonic: string): Promise<SigningCosmWasmClient> {
const { prefix, gasPrice } = config;

// Get Wallet
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix });
// Setup signer
const offlineSigner = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix });

// Init SigningCosmWasmClient client
const client = await SigningCosmWasmClient.connectWithSigner(config.rpcEndpoint, wallet, {
const client = await SigningCosmWasmClient.connectWithSigner(config.rpcEndpoint, offlineSigner, {
prefix,
gasPrice,
});
Expand Down
1 change: 1 addition & 0 deletions src/ledger-amino.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { LedgerSigner } from "@cosmjs/ledger-amino";
2 changes: 1 addition & 1 deletion src/stargate.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Block, GasPrice, IndexedTx, QueryClient } from "@cosmjs/stargate";
export { Block, GasPrice, IndexedTx, makeCosmoshubPath, QueryClient } from "@cosmjs/stargate";
121 changes: 118 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
chalk "^2.0.0"
js-tokens "^4.0.0"

"@babel/runtime@^7.11.2":
version "7.17.2"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.17.2.tgz#66f68591605e59da47523c631416b18508779941"
integrity sha512-hzeyJyMA1YGdJTuWU0e/j4wKXrU4OMFvY2MSlaI9B7VQb0r5cxTE3EAIS2Q7Tn2RIcDkRvTA/v2JsAEhxe99uw==
dependencies:
regenerator-runtime "^0.13.4"

"@confio/ics23@^0.6.3":
version "0.6.5"
resolved "https://registry.npmjs.org/@confio/ics23/-/ics23-0.6.5.tgz"
Expand Down Expand Up @@ -101,6 +108,19 @@
"@cosmjs/stream" "0.27.1"
xstream "^11.14.0"

"@cosmjs/ledger-amino@^0.27.1":
version "0.27.1"
resolved "https://registry.yarnpkg.com/@cosmjs/ledger-amino/-/ledger-amino-0.27.1.tgz#4f7178477dff203a770c3ee76a37d8569be95696"
integrity sha512-MbRw37+q37xP6ICQZll1ulFkqW/rpUgkatnA0aOuFfvf9DivRO0XRXGM7sw/3aKInxt9+8M1DGNFWM3HchwExw==
dependencies:
"@cosmjs/amino" "0.27.1"
"@cosmjs/crypto" "0.27.1"
"@cosmjs/encoding" "0.27.1"
"@cosmjs/math" "0.27.1"
"@cosmjs/utils" "0.27.1"
ledger-cosmos-js "^2.1.8"
semver "^7.3.2"

"@cosmjs/[email protected]":
version "0.27.1"
resolved "https://registry.npmjs.org/@cosmjs/math/-/math-0.27.1.tgz"
Expand Down Expand Up @@ -204,6 +224,74 @@
resolved "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz"
integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==

"@ledgerhq/devices@^5.51.1":
version "5.51.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/devices/-/devices-5.51.1.tgz#d741a4a5d8f17c2f9d282fd27147e6fe1999edb7"
integrity sha512-4w+P0VkbjzEXC7kv8T1GJ/9AVaP9I6uasMZ/JcdwZBS3qwvKo5A5z9uGhP5c7TvItzcmPb44b5Mw2kT+WjUuAA==
dependencies:
"@ledgerhq/errors" "^5.50.0"
"@ledgerhq/logs" "^5.50.0"
rxjs "6"
semver "^7.3.5"

"@ledgerhq/devices@^6.24.1":
version "6.24.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/devices/-/devices-6.24.1.tgz#9696d7831aa1a1a8204cdfa55df13f892b7da162"
integrity sha512-6SNXWXxojUF6WKXMVIbRs15Mveg+9k0RKJK/PKlwZh929Lnr/NcbONWdwPjWKZAp1g82eEPT4jIkG6qc4QXlcA==
dependencies:
"@ledgerhq/errors" "^6.10.0"
"@ledgerhq/logs" "^6.10.0"
rxjs "6"
semver "^7.3.5"

"@ledgerhq/errors@^5.50.0":
version "5.50.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/errors/-/errors-5.50.0.tgz#e3a6834cb8c19346efca214c1af84ed28e69dad9"
integrity sha512-gu6aJ/BHuRlpU7kgVpy2vcYk6atjB4iauP2ymF7Gk0ez0Y/6VSMVSJvubeEQN+IV60+OBK0JgeIZG7OiHaw8ow==

"@ledgerhq/errors@^6.10.0":
version "6.10.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/errors/-/errors-6.10.0.tgz#dda9127b65f653fbb2f74a55e8f0e550d69de6e4"
integrity sha512-fQFnl2VIXh9Yd41lGjReCeK+Q2hwxQJvLZfqHnKqWapTz68NHOv5QcI0OHuZVNEbv0xhgdLhi5b65kgYeQSUVg==

"@ledgerhq/[email protected]":
version "6.24.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-webusb/-/hw-transport-webusb-6.24.1.tgz#9267b6cb23ba991ce3a5debb15d162125a772b1b"
integrity sha512-+bAkVF/5MbbGIXobtmc5st/gFEjSRqACk+UPJGSxT21Z2SVm+FgG0Bui5wy24H+Ts/tC4IA3Mff8cz4PGbZhPA==
dependencies:
"@ledgerhq/devices" "^6.24.1"
"@ledgerhq/errors" "^6.10.0"
"@ledgerhq/hw-transport" "^6.24.1"
"@ledgerhq/logs" "^6.10.0"

"@ledgerhq/hw-transport@^5.25.0":
version "5.51.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport/-/hw-transport-5.51.1.tgz#8dd14a8e58cbee4df0c29eaeef983a79f5f22578"
integrity sha512-6wDYdbWrw9VwHIcoDnqWBaDFyviyjZWv6H9vz9Vyhe4Qd7TIFmbTl/eWs6hZvtZBza9K8y7zD8ChHwRI4s9tSw==
dependencies:
"@ledgerhq/devices" "^5.51.1"
"@ledgerhq/errors" "^5.50.0"
events "^3.3.0"

"@ledgerhq/hw-transport@^6.24.1":
version "6.24.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport/-/hw-transport-6.24.1.tgz#5e787268e6d5ce4f9f0d53b0d520c1f071c2d1ae"
integrity sha512-cOhxkQJrN7DvPFLLXAS2nqAZ7NIDaFqnbgu9ugTccgbJm2/z7ClRZX/uQoI4FscswZ47MuJQdXqz4nK48phteQ==
dependencies:
"@ledgerhq/devices" "^6.24.1"
"@ledgerhq/errors" "^6.10.0"
events "^3.3.0"

"@ledgerhq/logs@^5.50.0":
version "5.50.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/logs/-/logs-5.50.0.tgz#29c6419e8379d496ab6d0426eadf3c4d100cd186"
integrity sha512-swKHYCOZUGyVt4ge0u8a7AwNcA//h4nx5wIi0sruGye1IJ5Cva0GyK9L2/WdX+kWVTKp92ZiEo1df31lrWGPgA==

"@ledgerhq/logs@^6.10.0":
version "6.10.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/logs/-/logs-6.10.0.tgz#c012c1ecc1a0e53d50e6af381618dca5268461c1"
integrity sha512-lLseUPEhSFUXYTKj6q7s2O3s2vW2ebgA11vMAlKodXGf5AFw4zUoEbTz9CoFOC9jS6xY4Qr8BmRnxP/odT4Uuw==

"@nodelib/[email protected]":
version "2.1.5"
resolved "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz"
Expand Down Expand Up @@ -980,6 +1068,11 @@ esutils@^2.0.2:
resolved "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==

events@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==

fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
version "3.1.3"
resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz"
Expand Down Expand Up @@ -1396,6 +1489,16 @@ json5@^1.0.1:
dependencies:
minimist "^1.2.0"

ledger-cosmos-js@^2.1.8:
version "2.1.8"
resolved "https://registry.yarnpkg.com/ledger-cosmos-js/-/ledger-cosmos-js-2.1.8.tgz#b409ecd1e77f630e6fb212a9f602fe5c6e8f054b"
integrity sha512-Gl7SWMq+3R9OTkF1hLlg5+1geGOmcHX9OdS+INDsGNxSiKRWlsWCvQipGoDnRIQ6CPo2i/Ze58Dw0Mt/l3UYyA==
dependencies:
"@babel/runtime" "^7.11.2"
"@ledgerhq/hw-transport" "^5.25.0"
bech32 "^1.1.4"
ripemd160 "^2.0.2"

levn@^0.4.1:
version "0.4.1"
resolved "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz"
Expand Down Expand Up @@ -1716,6 +1819,11 @@ readonly-date@^1.0.0:
resolved "https://registry.npmjs.org/readonly-date/-/readonly-date-1.0.0.tgz"
integrity sha512-tMKIV7hlk0h4mO3JTmmVuIlJVXjKk3Sep9Bf5OH0O+758ruuVkUy2J9SttDLm91IEX/WHlXPSpxMGjPj4beMIQ==

regenerator-runtime@^0.13.4:
version "0.13.9"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52"
integrity sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==

regexpp@^3.0.0, regexpp@^3.1.0, regexpp@^3.2.0:
version "3.2.0"
resolved "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz"
Expand Down Expand Up @@ -1767,6 +1875,13 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"

rxjs@6:
version "6.6.7"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.7.tgz#90ac018acabf491bf65044235d5863c4dab804c9"
integrity sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==
dependencies:
tslib "^1.9.0"

safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0:
version "5.2.1"
resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz"
Expand All @@ -1777,7 +1892,7 @@ semver@^6.1.0:
resolved "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

semver@^7.2.1, semver@^7.3.5:
semver@^7.2.1, semver@^7.3.2, semver@^7.3.5:
version "7.3.5"
resolved "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz"
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
Expand Down Expand Up @@ -1938,9 +2053,9 @@ tsconfig-paths@^3.12.0:
minimist "^1.2.0"
strip-bom "^3.0.0"

tslib@^1.8.1:
tslib@^1.8.1, tslib@^1.9.0:
version "1.14.1"
resolved "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tsutils@^3.21.0:
Expand Down

0 comments on commit c82a3fd

Please sign in to comment.