From b84c0412834ac797c6d79e96bef85299f9a3abe6 Mon Sep 17 00:00:00 2001 From: Xiphiar Date: Sun, 1 Oct 2023 22:31:06 -0400 Subject: [PATCH 1/2] add ledger integration example --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/README.md b/README.md index ed3971e0..b89d8e6b 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ - [Deep linking](#deep-linking) - [Leap Cosmos Wallet](#leap-cosmos-wallet) - [StarShell Wallet](#starshell-wallet) + - [Ledger Wallet](#ledger-wallet) - [API](#api) - [Wallet](#wallet) - [Importing account from mnemonic](#importing-account-from-mnemonic) @@ -382,6 +383,55 @@ Links: - Official StarShell Website » +## Ledger Wallet + +`@cosmjs/ledger-amino` can be used to sign transactions with a Ledger wallet running the Cosmos app. + +```ts +import { SecretNetworkClient } from 'secretjs'; +import { makeCosmoshubPath } from "@cosmjs/amino"; +import { LedgerSigner } from "@cosmjs/ledger-amino"; + +// NodeJS only +import TransportNodeHid from "@ledgerhq/hw-transport-node-hid"; + +// Browser only +//import TransportNodeHid from "@ledgerhq/hw-transport-webusb"; + +const interactiveTimeout = 120_000; +const accountIndex = 0; +const cosmosPath = makeCosmoshubPath(accountIndex); + +const ledgerTransport = await TransportNodeHid.create(interactiveTimeout, interactiveTimeout); +const ledgerSigner = new LedgerSigner( + ledgerTransport, + { + testModeAllowed: true, + hdPaths: [cosmosPath], + prefix: 'secret' + } +); +const [{ address }] = await signer.getAccounts(); + +const client = new SecretNetworkClient({ + url: "TODO get from https://github.com/scrtlabs/api-registry", + chainId: "secret-4", + wallet: ledgerSigner, + walletAddress: address, +}); +``` + +Notes: + +1. Use the appropriate `hw-transport` package for your environment (Node or Browser) +2. The Ledger Cosmos app only supports coin type 118 +3. You might want to pass `encryptionSeed` to `SecretNetworkClient.create()` to use the same encryption key for the user across sessions. This value should be a true random 32 byte number that is stored securly in your app, such that only the user can decrypt it. This can also be a `sha256(user_password)` but might impair UX. +4. See Keplr's [`getOfflineSignerOnlyAmino()`](#windowkeplrgetofflinesigneronlyamino) for list of unsupported transactions. + +Links: + +- @cosmjs/ledger-amino Documentation » + # API ## Wallet From b0dcfc171be06c89666837e179b724ff69481fc3 Mon Sep 17 00:00:00 2001 From: Xiphiar Date: Sun, 1 Oct 2023 22:32:59 -0400 Subject: [PATCH 2/2] fix links and change gRPC-web references --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b89d8e6b..d0b3127c 100644 --- a/README.md +++ b/README.md @@ -105,18 +105,18 @@ Follow the instruction of [react-native-get-random-values](https://www.npmjs.com # Usage Examples -Note: Public gRPC-web endpoints can be found in https://github.com/scrtlabs/api-registry for both mainnet and testnet. +Note: Public LCD endpoints can be found in https://github.com/scrtlabs/api-registry for both mainnet and testnet. For a lot more usage examples [refer to the tests](./test/test.ts). ## Sending Queries ```ts -import { SecretNetworkClient, grpc } from "secretjs"; +import { SecretNetworkClient } from "secretjs"; const url = "TODO get from https://github.com/scrtlabs/api-registry"; -// To create a readonly secret.js client, just pass in a gRPC-web endpoint +// To create a readonly secret.js client, just pass in a LCD endpoint const secretjs = new SecretNetworkClient({ url, chainId: "secret-4", @@ -211,7 +211,7 @@ Notes: 1. MetaMask supports mobile! 2. MetaMask supports Ledger. 3. You might want to pass `encryptionSeed` to `SecretNetworkClient.create()` to use the same encryption key for the user across sessions. This value should be a true random 32 byte number that is stored securly in your app, such that only the user can decrypt it. This can also be a `sha256(user_password)` but might impair UX. -4. See Keplr's [`getOfflineSignerOnlyAmino()`](#getofflinesigneronlyamino) for list of unsupported transactions. +4. See Keplr's [`getOfflineSignerOnlyAmino()`](#windowkeplrgetofflinesigneronlyamino) for list of unsupported transactions. @@ -270,9 +270,9 @@ Links: TLDR: -- [`getOfflineSignerOnlyAmino()`](#getofflinesigneronlyamino): The recommended way. Supports Ledger, has a nice UI. -- [`getOfflineSigner()`](#getofflinesigner): No Ledger support, ugly UI, can send IBC **relayer** txs and submit IBC gov proposals. -- [`getOfflineSignerAuto()`](#getofflinesignerauto): If Ledger alias for `getOfflineSignerOnlyAmino()`, otherwise alias for `getOfflineSigner()`. +- [`getOfflineSignerOnlyAmino()`](#windowkeplrgetofflinesigneronlyamino): The recommended way. Supports Ledger, has a nice UI. +- [`getOfflineSigner()`](#windowkeplrgetofflinesigner): No Ledger support, ugly UI, can send IBC **relayer** txs and submit IBC gov proposals. +- [`getOfflineSignerAuto()`](#windowkeplrgetofflinesignerauto): If Ledger alias for `getOfflineSignerOnlyAmino()`, otherwise alias for `getOfflineSigner()`. #### `window.keplr.getOfflineSignerOnlyAmino()` @@ -474,7 +474,7 @@ import { SecretNetworkClient } from "secretjs"; const url = "TODO get from https://github.com/scrtlabs/api-registry"; -// To create a readonly secret.js client, just pass in a gRPC-web endpoint +// To create a readonly secret.js client, just pass in a LCD endpoint const secretjs = new SecretNetworkClient({ chainId: "secret-4", url,