mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
launchpad-ledger: Fully support multiple accounts
This commit is contained in:
parent
55602522ab
commit
7b005b4244
@ -122,7 +122,11 @@ export class LaunchpadLedger {
|
||||
}
|
||||
|
||||
async getPubkeys(): Promise<readonly Uint8Array[]> {
|
||||
return Promise.all(this.hdPaths.map(async (hdPath) => this.getPubkey(hdPath)));
|
||||
return this.hdPaths.reduce(
|
||||
(promise: Promise<readonly Uint8Array[]>, hdPath) =>
|
||||
promise.then(async (pubkeys) => [...pubkeys, await this.getPubkey(hdPath)]),
|
||||
Promise.resolve([]),
|
||||
);
|
||||
}
|
||||
|
||||
async getCosmosAddress(pubkey?: Uint8Array): Promise<string> {
|
||||
|
@ -1,4 +1,10 @@
|
||||
import { AccountData, encodeSecp256k1Signature, OfflineSigner, StdSignature } from "@cosmjs/launchpad";
|
||||
import {
|
||||
AccountData,
|
||||
encodeSecp256k1Signature,
|
||||
makeCosmoshubPath,
|
||||
OfflineSigner,
|
||||
StdSignature,
|
||||
} from "@cosmjs/launchpad";
|
||||
|
||||
import { LaunchpadLedger, LaunchpadLedgerOptions } from "./launchpadledger";
|
||||
|
||||
@ -27,7 +33,12 @@ export class LedgerSigner implements OfflineSigner {
|
||||
return this.accounts;
|
||||
}
|
||||
|
||||
public async sign(address: string, message: Uint8Array): Promise<StdSignature> {
|
||||
public async sign(
|
||||
address: string,
|
||||
message: Uint8Array,
|
||||
_prehashType?: "sha256" | "sha512" | null,
|
||||
accountNumber = 0,
|
||||
): Promise<StdSignature> {
|
||||
await this.ledger.connect();
|
||||
|
||||
const accounts = this.accounts || (await this.getAccounts());
|
||||
@ -37,7 +48,8 @@ export class LedgerSigner implements OfflineSigner {
|
||||
throw new Error(`Address ${address} not found in wallet`);
|
||||
}
|
||||
|
||||
const signature = await this.ledger.sign(message);
|
||||
const hdPath = makeCosmoshubPath(accountNumber);
|
||||
const signature = await this.ledger.sign(message, hdPath);
|
||||
return encodeSecp256k1Signature(accountForAddress.pubkey, signature);
|
||||
}
|
||||
}
|
||||
|
@ -5,5 +5,10 @@ export declare class LedgerSigner implements OfflineSigner {
|
||||
private accounts?;
|
||||
constructor(options?: LaunchpadLedgerOptions);
|
||||
getAccounts(): Promise<readonly AccountData[]>;
|
||||
sign(address: string, message: Uint8Array): Promise<StdSignature>;
|
||||
sign(
|
||||
address: string,
|
||||
message: Uint8Array,
|
||||
_prehashType?: "sha256" | "sha512" | null,
|
||||
accountNumber?: number,
|
||||
): Promise<StdSignature>;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user