Skip to content

Commit

Permalink
fix: ledger support
Browse files Browse the repository at this point in the history
Signed-off-by: Norman Meier <[email protected]>
  • Loading branch information
n0izn0iz committed Jan 29, 2024
1 parent af91899 commit 7c5617f
Showing 1 changed file with 30 additions and 33 deletions.
63 changes: 30 additions & 33 deletions packages/utils/keplr.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OfflineSigner } from "@cosmjs/proto-signing";
import { OfflineDirectSigner, OfflineSigner } from "@cosmjs/proto-signing";
import {
Window as KeplrWindow,
OfflineAminoSigner as KeplrOfflineAminoSigner,
Expand All @@ -21,38 +21,35 @@ export const getKeplr = () => {
export const convertKeplrSigner = (
keplrSigner: KeplrOfflineAminoSigner | KeplrOfflineDirectSigner,
): OfflineSigner => {
const signer: OfflineSigner = {
getAccounts: async () => {
return keplrSigner.getAccounts();
},
signDirect: async (signerAddress, signDoc) => {
if (!("signDirect" in keplrSigner)) {
throw new Error("signDirect not implemented");
}
const convertedSignDoc: KeplrSignDoc = {
...signDoc,
accountNumber: Long.fromString(signDoc.accountNumber.toString()),
};
const response = await keplrSigner.signDirect(
signerAddress,
convertedSignDoc,
);
return {
...response,
signed: {
...response.signed,
accountNumber: BigInt(response.signed.accountNumber.toString()),
},
};
},
signAmino: async (signerAddress, tx) => {
if (!("signAmino" in keplrSigner)) {
throw new Error("signAmino not implemented");
}
return keplrSigner.signAmino(signerAddress, tx);
},
};
return signer;
if ("signDirect" in keplrSigner) {
const signer: OfflineDirectSigner = {
getAccounts: async () => {
return keplrSigner.getAccounts();
},
signDirect: async (signerAddress, signDoc) => {
const convertedSignDoc: KeplrSignDoc = {
...signDoc,
accountNumber: Long.fromString(signDoc.accountNumber.toString()),
};
const response = await keplrSigner.signDirect(
signerAddress,
convertedSignDoc,
);
return {
...response,
signed: {
...response.signed,
accountNumber: BigInt(response.signed.accountNumber.toString()),
},
};
},
};
return signer;
}
if ("signAmino" in keplrSigner) {
return keplrSigner;
}
throw new Error("unexpected signer shape");
};

export const keplrSignArbitrary = async (
Expand Down

0 comments on commit 7c5617f

Please sign in to comment.