-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
149 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { | ||
IBBNProvider, | ||
Keplr, | ||
OfflineAminoSigner, | ||
OfflineDirectSigner, | ||
} from "@keplr-wallet/types"; | ||
|
||
const BabylonChainInfo = { | ||
chainId: "bbn-test-5", | ||
chainName: "Babylon Phase-2 Testnet", | ||
chainSymbolImageUrl: | ||
"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png", | ||
rpc: "https://babylon-testnet-rpc.nodes.guru", | ||
rest: "https://babylon-testnet-api.nodes.guru", | ||
nodeProvider: { | ||
name: "NodesGuru", | ||
email: "[email protected]", | ||
website: "https://nodes.guru/", | ||
}, | ||
bip44: { | ||
coinType: 118, | ||
}, | ||
bech32Config: { | ||
bech32PrefixAccAddr: "bbn", | ||
bech32PrefixAccPub: "bbnpub", | ||
bech32PrefixValAddr: "bbnvaloper", | ||
bech32PrefixValPub: "bbnvaloperpub", | ||
bech32PrefixConsAddr: "bbnvalcons", | ||
bech32PrefixConsPub: "bbnvalconspub", | ||
}, | ||
currencies: [ | ||
{ | ||
coinDenom: "BABY", | ||
coinMinimalDenom: "ubbn", | ||
coinDecimals: 6, | ||
coinImageUrl: | ||
"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png", | ||
}, | ||
], | ||
feeCurrencies: [ | ||
{ | ||
coinDenom: "BABY", | ||
coinMinimalDenom: "ubbn", | ||
coinDecimals: 6, | ||
coinImageUrl: | ||
"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png", | ||
gasPriceStep: { | ||
low: 0.007, | ||
average: 0.007, | ||
high: 0.01, | ||
}, | ||
}, | ||
], | ||
stakeCurrency: { | ||
coinDenom: "BABY", | ||
coinMinimalDenom: "ubbn", | ||
coinDecimals: 6, | ||
coinImageUrl: | ||
"https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/bbn-test/chain.png", | ||
}, | ||
features: ["cosmwasm"], | ||
}; | ||
|
||
export class KeplrBBNProvider implements IBBNProvider { | ||
constructor(protected readonly keplr: Keplr) {} | ||
|
||
async connectWallet(): Promise<void> { | ||
await this.keplr.experimentalSuggestChain(BabylonChainInfo); | ||
await this.keplr.enable(BabylonChainInfo.chainId); | ||
} | ||
|
||
async getAddress(): Promise<string> { | ||
await this.keplr.experimentalSuggestChain(BabylonChainInfo); | ||
await this.keplr.enable(BabylonChainInfo.chainId); | ||
return (await this.keplr.getKey(BabylonChainInfo.chainId)).bech32Address; | ||
} | ||
|
||
async getOfflineSigner(): Promise<OfflineAminoSigner & OfflineDirectSigner> { | ||
return this.keplr.getOfflineSigner(BabylonChainInfo.chainId); | ||
} | ||
|
||
async getPublicKeyHex(): Promise<string> { | ||
await this.keplr.experimentalSuggestChain(BabylonChainInfo); | ||
await this.keplr.enable(BabylonChainInfo.chainId); | ||
return Array.from( | ||
(await this.keplr.getKey(BabylonChainInfo.chainId)).pubKey | ||
) | ||
.map((byte) => byte.toString(16).padStart(2, "0")) | ||
.join(""); | ||
} | ||
|
||
async getWalletProviderIcon(): Promise<string> { | ||
return process.env["KEPLR_EXT_EIP6963_PROVIDER_INFO_ICON"] || ""; | ||
} | ||
|
||
async getWalletProviderName(): Promise<string> { | ||
return "Keplr"; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { OfflineAminoSigner, OfflineDirectSigner } from "./cosmjs"; | ||
|
||
export interface IBBNProvider { | ||
/** | ||
* Connects to the wallet and returns the instance of the wallet provider. | ||
* @returns A promise that resolves to an instance of the wrapper wallet provider. | ||
* @throws An error if the wallet is not installed or if connection fails. | ||
*/ | ||
connectWallet(): Promise<void>; | ||
|
||
/** | ||
* Gets the address of the connected wallet. | ||
* @returns A promise that resolves to the address of the connected wallet. | ||
*/ | ||
getAddress(): Promise<string>; | ||
|
||
/** | ||
* Gets the public key of the connected wallet. | ||
* @returns A promise that resolves to the public key of the connected wallet. | ||
*/ | ||
getPublicKeyHex(): Promise<string>; | ||
|
||
/** | ||
* Gets the name of the wallet provider. | ||
* @returns A promise that resolves to the name of the wallet provider. | ||
*/ | ||
getWalletProviderName(): Promise<string>; | ||
|
||
/** | ||
* Gets the icon of the wallet provider. | ||
* @returns A promise that resolves to the icon of the wallet provider. | ||
*/ | ||
getWalletProviderIcon(): Promise<string>; | ||
|
||
/** | ||
* Retrieves an offline signer that supports both Amino and Direct signing methods. | ||
* This signer is used for signing transactions offline before broadcasting them to the network. | ||
* | ||
* @returns {Promise<OfflineAminoSigner & OfflineDirectSigner>} A promise that resolves to a signer supporting both Amino and Direct signing | ||
* @throws {Error} If wallet connection is not established or signer cannot be retrieved | ||
*/ | ||
getOfflineSigner(): Promise<OfflineAminoSigner & OfflineDirectSigner>; | ||
} |
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