Rename launchpadledger (#1056)

* Rename LaunchpadLedger to LedgerConnector

* Added changelog entry

* Update CHANGELOG.md

Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com>

* Rename property ledger to connector

Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com>
This commit is contained in:
Milan Steiner 2022-02-22 11:43:16 +01:00 committed by GitHub
parent 48aeb1ddeb
commit 9b80dff493
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 12 deletions

View File

@ -36,8 +36,10 @@ and this project adheres to
you if multiple different protobuf type URLs map to the same Amino type
identifier which should not be the case anyways.
- @cosmjs/stargate: Added support for slashing queries ([#927])
- @cosmjs/ledger-amino: Renamed `LaunchpadLedger` to `LedgerConnector` ([#955])
[#927]: https://github.com/cosmos/cosmjs/issues/927
[#955]: https://github.com/cosmos/cosmjs/issues/955
[#989]: https://github.com/cosmos/cosmjs/issues/989
[#994]: https://github.com/cosmos/cosmjs/issues/994
[#1011]: https://github.com/cosmos/cosmjs/issues/1011

View File

@ -1,2 +1,2 @@
export { AddressAndPubkey, LaunchpadLedger } from "./launchpadledger";
export { AddressAndPubkey, LedgerConnector } from "./ledgerconnector";
export { LedgerSigner } from "./ledgersigner";

View File

@ -28,7 +28,7 @@ const cosmosBech32Prefix = "cosmos";
const cosmosLedgerAppName = "Cosmos";
const requiredCosmosAppVersion = "1.5.3";
export interface LaunchpadLedgerOptions {
export interface LedgerConnectorOptions {
readonly hdPaths?: readonly HdPath[];
readonly prefix?: string;
readonly testModeAllowed?: boolean;
@ -57,7 +57,7 @@ export interface AddressAndPubkey {
readonly pubkey: Secp256k1Pubkey;
}
export class LaunchpadLedger {
export class LedgerConnector {
private readonly testModeAllowed: boolean;
private readonly hdPaths: readonly HdPath[];
private readonly prefix: string;
@ -65,7 +65,7 @@ export class LaunchpadLedger {
private readonly minLedgerAppVersion: string;
private readonly app: CosmosApp;
public constructor(transport: Transport, options: LaunchpadLedgerOptions = {}) {
public constructor(transport: Transport, options: LedgerConnectorOptions = {}) {
const defaultOptions = {
hdPaths: [cosmosHdPath],
prefix: cosmosBech32Prefix,

View File

@ -10,25 +10,25 @@ import {
import { HdPath } from "@cosmjs/crypto";
import Transport from "@ledgerhq/hw-transport";
import { AddressAndPubkey, LaunchpadLedger, LaunchpadLedgerOptions } from "./launchpadledger";
import { AddressAndPubkey, LedgerConnector, LedgerConnectorOptions } from "./ledgerconnector";
export class LedgerSigner implements OfflineAminoSigner {
private readonly ledger: LaunchpadLedger;
private readonly connector: LedgerConnector;
private readonly hdPaths: readonly HdPath[];
private accounts?: readonly AccountData[];
public constructor(transport: Transport, options: LaunchpadLedgerOptions = {}) {
public constructor(transport: Transport, options: LedgerConnectorOptions = {}) {
this.hdPaths = options.hdPaths || [makeCosmoshubPath(0)];
this.ledger = new LaunchpadLedger(transport, options);
this.connector = new LedgerConnector(transport, options);
}
public async getAccounts(): Promise<readonly AccountData[]> {
if (!this.accounts) {
const pubkeys = await this.ledger.getPubkeys();
const pubkeys = await this.connector.getPubkeys();
this.accounts = await Promise.all(
pubkeys.map(async (pubkey) => ({
algo: "secp256k1" as const,
address: await this.ledger.getCosmosAddress(pubkey),
address: await this.connector.getCosmosAddress(pubkey),
pubkey: pubkey,
})),
);
@ -46,7 +46,7 @@ export class LedgerSigner implements OfflineAminoSigner {
* @param path The HD path to show the address for. If unset, this is the first account.
*/
public async showAddress(path?: HdPath): Promise<AddressAndPubkey> {
return this.ledger.showAddress(path);
return this.connector.showAddress(path);
}
public async signAmino(signerAddress: string, signDoc: StdSignDoc): Promise<AminoSignResponse> {
@ -60,7 +60,7 @@ export class LedgerSigner implements OfflineAminoSigner {
const message = serializeSignDoc(signDoc);
const accountForAddress = accounts[accountIndex];
const hdPath = this.hdPaths[accountIndex];
const signature = await this.ledger.sign(message, hdPath);
const signature = await this.connector.sign(message, hdPath);
return {
signed: signDoc,
signature: encodeSecp256k1Signature(accountForAddress.pubkey, signature),