launchpad-ledger: Refactor LedgerSigner options
This commit is contained in:
parent
d43ada9660
commit
738f0b3f65
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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>;
|
||||
|
||||
@ -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 {};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user