mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 13:47:12 +00:00
adding show address in ledgerSigner
This commit is contained in:
parent
5743d55229
commit
450480791b
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,6 +14,7 @@ node_modules/
|
|||||||
|
|
||||||
# IDE-specific
|
# IDE-specific
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
|
||||||
# demo mnemonics from cli
|
# demo mnemonics from cli
|
||||||
*.key
|
*.key
|
||||||
|
@ -12,6 +12,7 @@ and this project adheres to
|
|||||||
JavaScript objects and the JSON representation of `cosmwasm_std::Binary`
|
JavaScript objects and the JSON representation of `cosmwasm_std::Binary`
|
||||||
(base64).
|
(base64).
|
||||||
- @cosmjs/cosmwasm-stargate: Export `WasmExtension` and `setupWasmExtension`.
|
- @cosmjs/cosmwasm-stargate: Export `WasmExtension` and `setupWasmExtension`.
|
||||||
|
- @cosmjs/ledger-amino: Added `showAddress` in LedgerSigner.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import { fromUtf8 } from "@cosmjs/encoding";
|
|||||||
import { assert } from "@cosmjs/utils";
|
import { assert } from "@cosmjs/utils";
|
||||||
import Transport from "@ledgerhq/hw-transport";
|
import Transport from "@ledgerhq/hw-transport";
|
||||||
import CosmosApp, {
|
import CosmosApp, {
|
||||||
|
AddressAndPublicKeyResponse,
|
||||||
AppInfoResponse,
|
AppInfoResponse,
|
||||||
PublicKeyResponse,
|
PublicKeyResponse,
|
||||||
SignResponse,
|
SignResponse,
|
||||||
@ -166,6 +167,16 @@ export class LaunchpadLedger {
|
|||||||
await this.verifyCosmosAppIsOpen();
|
await this.verifyCosmosAppIsOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async verifyAddress(hdPath?: HdPath): Promise<AddressAndPublicKeyResponse> {
|
||||||
|
await this.verifyDeviceIsReady();
|
||||||
|
|
||||||
|
const hdPathToUse = hdPath || this.hdPaths[0];
|
||||||
|
// ledger-cosmos-js hardens the first three indices
|
||||||
|
const response = await this.app.showAddressAndPubKey(unharden(hdPathToUse), this.prefix);
|
||||||
|
this.handleLedgerErrors(response);
|
||||||
|
return response as AddressAndPublicKeyResponse;
|
||||||
|
}
|
||||||
|
|
||||||
private handleLedgerErrors(
|
private handleLedgerErrors(
|
||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,7 @@ import {
|
|||||||
encodeSecp256k1Signature,
|
encodeSecp256k1Signature,
|
||||||
makeCosmoshubPath,
|
makeCosmoshubPath,
|
||||||
OfflineAminoSigner,
|
OfflineAminoSigner,
|
||||||
|
Secp256k1Pubkey,
|
||||||
serializeSignDoc,
|
serializeSignDoc,
|
||||||
StdSignDoc,
|
StdSignDoc,
|
||||||
} from "@cosmjs/amino";
|
} from "@cosmjs/amino";
|
||||||
@ -12,6 +13,11 @@ import Transport from "@ledgerhq/hw-transport";
|
|||||||
|
|
||||||
import { LaunchpadLedger, LaunchpadLedgerOptions } from "./launchpadledger";
|
import { LaunchpadLedger, LaunchpadLedgerOptions } from "./launchpadledger";
|
||||||
|
|
||||||
|
export interface AddressAndPubkey {
|
||||||
|
readonly address: string;
|
||||||
|
readonly pubkey: Secp256k1Pubkey;
|
||||||
|
}
|
||||||
|
|
||||||
export class LedgerSigner implements OfflineAminoSigner {
|
export class LedgerSigner implements OfflineAminoSigner {
|
||||||
private readonly ledger: LaunchpadLedger;
|
private readonly ledger: LaunchpadLedger;
|
||||||
private readonly hdPaths: readonly HdPath[];
|
private readonly hdPaths: readonly HdPath[];
|
||||||
@ -37,6 +43,19 @@ export class LedgerSigner implements OfflineAminoSigner {
|
|||||||
return this.accounts;
|
return this.accounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async showAddress(path: HdPath): Promise<AddressAndPubkey> {
|
||||||
|
const response = await this.ledger.verifyAddress(path);
|
||||||
|
|
||||||
|
if (response.error_message) {
|
||||||
|
throw new Error(response.error_message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
address: response.address,
|
||||||
|
pubkey: response.compressed_pk,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public async signAmino(signerAddress: string, signDoc: StdSignDoc): Promise<AminoSignResponse> {
|
public async signAmino(signerAddress: string, signDoc: StdSignDoc): Promise<AminoSignResponse> {
|
||||||
const accounts = this.accounts || (await this.getAccounts());
|
const accounts = this.accounts || (await this.getAccounts());
|
||||||
const accountIndex = accounts.findIndex((account) => account.address === signerAddress);
|
const accountIndex = accounts.findIndex((account) => account.address === signerAddress);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user