-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use keplr wallet connect if possible
- Loading branch information
Showing
7 changed files
with
74 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 3 additions & 81 deletions
84
src/wallet/wallets/cosmostation/CosmostationWalletConnectV2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,4 @@ | ||
import { PlainMessage } from "@bufbuild/protobuf"; | ||
import { Secp256k1PubKey, Tx, broadcastTx } from "cosmes/client"; | ||
import { base64 } from "cosmes/codec"; | ||
import { | ||
CosmosBaseV1beta1Coin as Coin, | ||
CosmosTxV1beta1Fee as Fee, | ||
CosmosTxSigningV1beta1SignMode as SignMode, | ||
} from "cosmes/protobufs"; | ||
import { WalletName, WalletType } from "cosmes/wallet"; | ||
import { KeplrWalletConnectV2 } from "../keplr/KeplrWalletConnectV2"; | ||
|
||
import { WalletConnectV2 } from "../../walletconnect/WalletConnectV2"; | ||
import { | ||
ConnectedWallet, | ||
SignArbitraryResponse, | ||
UnsignedTx, | ||
} from "../ConnectedWallet"; | ||
|
||
export class CosmostationWalletConnectV2 extends ConnectedWallet { | ||
private readonly wc: WalletConnectV2; | ||
|
||
constructor( | ||
wc: WalletConnectV2, | ||
chainId: string, | ||
pubKey: Secp256k1PubKey, | ||
address: string, | ||
rpc: string, | ||
gasPrice: PlainMessage<Coin> | ||
) { | ||
super( | ||
WalletName.COSMOSTATION, | ||
WalletType.WALLETCONNECT, | ||
chainId, | ||
pubKey, | ||
address, | ||
rpc, | ||
gasPrice | ||
); | ||
this.wc = wc; | ||
} | ||
|
||
public async signArbitrary(_data: string): Promise<SignArbitraryResponse> { | ||
// ! Not implemented by Cosmostation | ||
throw new Error("Method not implemented."); | ||
} | ||
|
||
public async signAndBroadcastTx( | ||
{ msgs, memo }: UnsignedTx, | ||
fee: Fee, | ||
accountNumber: bigint, | ||
sequence: bigint | ||
): Promise<string> { | ||
const tx = new Tx({ | ||
chainId: this.chainId, | ||
pubKey: this.pubKey, | ||
msgs: msgs, | ||
}); | ||
const { signature, signed } = await this.wc.signAmino( | ||
this.chainId, | ||
this.address, | ||
tx.toStdSignDoc({ | ||
accountNumber, | ||
sequence, | ||
fee, | ||
memo, | ||
}) | ||
); | ||
// Since `sendTx` on WC isn't implemented yet, we have to broadcast manually | ||
return broadcastTx(this.rpc, { | ||
tx, | ||
sequence: BigInt(signed.sequence), | ||
fee: new Fee({ | ||
amount: signed.fee.amount as Coin[], | ||
gasLimit: BigInt(signed.fee.gas), | ||
payer: signed.fee.payer, | ||
granter: signed.fee.granter, | ||
}), | ||
signMode: SignMode.LEGACY_AMINO_JSON, | ||
signature: base64.decode(signature), | ||
memo: signed.memo, | ||
}); | ||
} | ||
} | ||
// Cosmostation's API is similar to Keplr. | ||
export const CosmostationWalletConnectV2 = KeplrWalletConnectV2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,4 @@ | ||
import { PlainMessage } from "@bufbuild/protobuf"; | ||
import { Secp256k1PubKey, Tx, broadcastTx } from "cosmes/client"; | ||
import { base64 } from "cosmes/codec"; | ||
import { | ||
CosmosBaseV1beta1Coin as Coin, | ||
CosmosTxV1beta1Fee as Fee, | ||
CosmosTxSigningV1beta1SignMode as SignMode, | ||
} from "cosmes/protobufs"; | ||
import { WalletName, WalletType } from "cosmes/wallet"; | ||
import { KeplrWalletConnectV2 } from "../keplr/KeplrWalletConnectV2"; | ||
|
||
import { WalletConnectV2 } from "../../walletconnect/WalletConnectV2"; | ||
import { | ||
ConnectedWallet, | ||
SignArbitraryResponse, | ||
UnsignedTx, | ||
} from "../ConnectedWallet"; | ||
|
||
export class LeapWalletConnectV2 extends ConnectedWallet { | ||
private readonly wc: WalletConnectV2; | ||
|
||
constructor( | ||
wc: WalletConnectV2, | ||
chainId: string, | ||
pubKey: Secp256k1PubKey, | ||
address: string, | ||
rpc: string, | ||
gasPrice: PlainMessage<Coin> | ||
) { | ||
super( | ||
WalletName.LEAP, | ||
WalletType.WALLETCONNECT, | ||
chainId, | ||
pubKey, | ||
address, | ||
rpc, | ||
gasPrice | ||
); | ||
this.wc = wc; | ||
} | ||
|
||
public async signArbitrary(_data: string): Promise<SignArbitraryResponse> { | ||
// ! Not implemented by Leap | ||
throw new Error("Method not implemented."); | ||
} | ||
|
||
public async signAndBroadcastTx( | ||
{ msgs, memo }: UnsignedTx, | ||
fee: Fee, | ||
accountNumber: bigint, | ||
sequence: bigint | ||
): Promise<string> { | ||
const tx = new Tx({ | ||
chainId: this.chainId, | ||
pubKey: this.pubKey, | ||
msgs: msgs, | ||
}); | ||
const { signature, signed } = await this.wc.signAmino( | ||
this.chainId, | ||
this.address, | ||
tx.toStdSignDoc({ | ||
accountNumber, | ||
sequence, | ||
fee, | ||
memo, | ||
}) | ||
); | ||
// Since `sendTx` on WC isn't implemented yet, we have to broadcast manually | ||
return broadcastTx(this.rpc, { | ||
tx, | ||
sequence: BigInt(signed.sequence), | ||
fee: new Fee({ | ||
amount: signed.fee.amount as Coin[], | ||
gasLimit: BigInt(signed.fee.gas), | ||
payer: signed.fee.payer, | ||
granter: signed.fee.granter, | ||
}), | ||
signMode: SignMode.LEGACY_AMINO_JSON, | ||
signature: base64.decode(signature), | ||
memo: signed.memo, | ||
}); | ||
} | ||
} | ||
// Leap's API is similar to Keplr. | ||
export const LeapWalletConnectV2 = KeplrWalletConnectV2; |