launchpad-ledger: Refactor LedgerSigner options

This commit is contained in:
willclarktech 2020-09-15 11:02:56 +02:00
parent d43ada9660
commit 738f0b3f65
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
4 changed files with 26 additions and 25 deletions

View File

@ -66,6 +66,12 @@ function unharden(hdPath: readonly Slip10RawIndex[]): number[] {
const cosmosHdPath = makeCosmoshubPath(0);
const cosmosBech32Prefix = "cosmos";
export interface LaunchpadLedgerOptions {
readonly hdPath?: readonly Slip10RawIndex[];
readonly prefix?: string;
readonly testModeAllowed?: boolean;
}
export class LaunchpadLedger {
private readonly testModeAllowed: boolean;
private readonly hdPath: readonly Slip10RawIndex[];
@ -74,11 +80,16 @@ export class LaunchpadLedger {
public readonly platform: string;
public readonly userAgent: string;
constructor(
{ testModeAllowed }: { testModeAllowed: boolean } = { testModeAllowed: false },
hdPath: readonly Slip10RawIndex[] = cosmosHdPath,
prefix: string = cosmosBech32Prefix,
) {
constructor(options: LaunchpadLedgerOptions = {}) {
const defaultOptions = {
hdPath: cosmosHdPath,
prefix: cosmosBech32Prefix,
testModeAllowed: false,
};
const { hdPath, prefix, testModeAllowed } = {
...defaultOptions,
...options,
};
this.testModeAllowed = testModeAllowed;
this.hdPath = hdPath;
this.prefix = prefix;

View File

@ -1,17 +1,13 @@
import { AccountData, encodeSecp256k1Signature, OfflineSigner, StdSignature } from "@cosmjs/launchpad";
import { LaunchpadLedger } from "./launchpadledger";
interface LedgerSignerOptions {
readonly testModeAllowed: boolean;
}
import { LaunchpadLedger, LaunchpadLedgerOptions } from "./launchpadledger";
export class LedgerSigner implements OfflineSigner {
private readonly ledger: LaunchpadLedger;
private address: string | undefined;
private pubkey: Uint8Array | undefined;
constructor(options?: LedgerSignerOptions) {
constructor(options?: LaunchpadLedgerOptions) {
this.ledger = new LaunchpadLedger(options);
}

View File

@ -1,5 +1,10 @@
/// <reference types="node" />
import { Slip10RawIndex } from "@cosmjs/crypto";
export interface LaunchpadLedgerOptions {
readonly hdPath?: readonly Slip10RawIndex[];
readonly prefix?: string;
readonly testModeAllowed?: boolean;
}
export declare class LaunchpadLedger {
private readonly testModeAllowed;
private readonly hdPath;
@ -7,15 +12,7 @@ export declare class LaunchpadLedger {
private cosmosApp;
readonly platform: string;
readonly userAgent: string;
constructor(
{
testModeAllowed,
}?: {
testModeAllowed: boolean;
},
hdPath?: readonly Slip10RawIndex[],
prefix?: string,
);
constructor(options?: LaunchpadLedgerOptions);
connect(timeout?: number): Promise<LaunchpadLedger>;
getCosmosAppVersion(): Promise<string>;
getPubKey(): Promise<Buffer>;

View File

@ -1,13 +1,10 @@
import { AccountData, OfflineSigner, StdSignature } from "@cosmjs/launchpad";
interface LedgerSignerOptions {
readonly testModeAllowed: boolean;
}
import { LaunchpadLedgerOptions } from "./launchpadledger";
export declare class LedgerSigner implements OfflineSigner {
private readonly ledger;
private address;
private pubkey;
constructor(options?: LedgerSignerOptions);
constructor(options?: LaunchpadLedgerOptions);
getAccounts(): Promise<readonly AccountData[]>;
sign(address: string, message: Uint8Array): Promise<StdSignature>;
}
export {};