Skip to content

Commit

Permalink
Support Keplr signArbitrary function in web3auth wallets.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Jun 7, 2023
1 parent 7c85e2f commit daaeb82
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@noahsaso/cosmodal",
"version": "0.11.1",
"version": "0.11.2",
"repository": {
"type": "git",
"url": "git+https://github.com/NoahSaso/cosmodal.git"
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type WalletClient = Pick<
| "getOfflineSigner"
| "getOfflineSignerAuto"
| "getOfflineSignerOnlyAmino"
| "signArbitrary"
> &
Partial<Pick<Keplr, "mode" | "experimentalSuggestChain">> & {
getKey: (chainId: string) => Promise<{
Expand Down
18 changes: 17 additions & 1 deletion src/wallets/web3auth/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OfflineAminoSigner } from "@cosmjs/amino"
import { OfflineAminoSigner, StdSignature } from "@cosmjs/amino"
import { fromBech32 } from "@cosmjs/encoding"
import { OfflineDirectSigner } from "@cosmjs/proto-signing"
import { makeADR36AminoSignDoc } from "@keplr-wallet/cosmos"
import { ChainInfo } from "@keplr-wallet/types"
import eccrypto from "@toruslabs/eccrypto"
import { LOGIN_PROVIDER_TYPE, OPENLOGIN_NETWORK } from "@toruslabs/openlogin"
Expand Down Expand Up @@ -250,6 +251,21 @@ export class Web3AuthClient implements WalletClient {
return this.getOfflineSigner(chainId)
}

async signArbitrary(
chainId: string,
signer: string,
data: string | Uint8Array
): Promise<StdSignature> {
// ADR 036
// https://docs.cosmos.network/v0.47/architecture/adr-036-arbitrary-signature
const signDoc = makeADR36AminoSignDoc(signer, data)

const offlineSigner = await this.getOfflineSignerOnlyAmino(chainId)
const { signature } = await offlineSigner.signAmino(signer, signDoc)

return signature
}

async getKey(chainId: string): Promise<{
name: string
algo: string
Expand Down

1 comment on commit daaeb82

@vercel
Copy link

@vercel vercel bot commented on daaeb82 Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

cosmodal – ./

cosmodal-noahsaso.vercel.app
cosmodal.vercel.app
cosmodal-git-main-noahsaso.vercel.app

Please sign in to comment.